Reputation: 11
octal numbers to binary numbers.
I want to convert this code to octal to binary how ..???
help me.
define variable bin as integer.
define variable dec as integer.
set dec label "Masukkan angka desimal" with side-labels.
repeat:
bin = dec modulo 2.
dec = dec / 2.
if bin = 1 then
dec = dec - 1.
else if dec < 1 then
quit.
display bin dec with frame a down.
end.
Upvotes: 1
Views: 268
Reputation: 14020
/* oct2bin.p
*
*/
function oct2bin returns character ( input octalString as character ):
define variable i as integer no-undo.
define variable n as integer no-undo.
define variable c as character no-undo.
define variable result as character no-undo.
n = length( octalString ).
if n < 2 or substring( octalString, 1, 1 ) <> "~\" then /* a valid octalString begins with "\" */
do:
message "valid octal strings must begin with ~\".
result = ?.
end.
else
do i = 2 to n:
c = substring( octalString, i, 1 ).
if asc( c ) < 48 or asc( c ) > 55 then /* a valid octalString only contains the digits 0 thru 7 */
do:
message c "is not a valid numeric character".
result = ?.
leave.
end.
case c:
when "0" then result = result + "000".
when "1" then result = result + "001".
when "2" then result = result + "010".
when "3" then result = result + "011".
when "4" then result = result + "100".
when "5" then result = result + "101".
when "6" then result = result + "110".
when "7" then result = result + "111".
end.
/* message octalString n c result. */
/* pause. */
end.
return result.
end.
define variable inputField as character no-undo.
do while true:
update inputField.
display oct2bin( inputField ).
end.
Upvotes: 1