[Stackoverflow] [Progress OpenEdge ABL] how to create convert octal to biner?

Status
Not open for further replies.
A

Arifudin Myf

Guest
I have a problem when I input numbers 2,5,7 the results are ok and when I input numbers 1,3,4,6 the results don't match. can anyone help me solve this problem..???

sorry, I separated the code because the template doesn't hold much, and I separate it like this

this code.


Code:
define variable oct as character.
define variable l-oct as integer.
define variable oktal as integer.
define variable l-oktal  as integer.
define variable count as integer.
define variable i as integer.
define variable bin as character.
define variable bin2 as character.

define variable temp as integer.

next


Code:
set oct label "Masukkan angka oktal".
do i = 1 to length(oct):
if substring(oct, i, 1) = "8" or substring(oct, i, 1) = "9" then do:
undo.
end.
end.
l-oct = length(oct).
count = length(oct) * 1.

do i = 1 to l-oct:
oktal = oktal + integer(substring(oct, i, 1)) * exp(8, count).
count = count - 1.
end.
display oktal with frame a down.

next


Code:
do while oktal <> 0:
temp = oktal modulo 16.
oktal = oktal / 16.
if temp = 8 or temp = 9 then do:
bin = bin + string(temp).
end.
if temp = 0 then do:
bin = bin + "000".
end.
else if temp = 1 then do:
bin = bin + "001".
end.
if temp = 2 then do:
bin = bin + "010".
end.
else if temp = 3 then do:
bin = bin + "011".
end.
else if temp = 4 then do:
bin = bin + "100".
end.
else if temp = 5 then do:
bin = bin + "101".
end.
else if temp = 6 then do:
bin = bin + "110".
end.
else if temp = 7 then do:
bin = bin + "111".
end.
else
bin = bin + string(temp).
end.

next


Code:
do i = length(bin) to 1 by -1:
bin2 = bin2 + substring(bin, i, 1).
end.

display bin2 with frame a down.

Continue reading...
 
Status
Not open for further replies.
Top