/* 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.