Category : Miscellaneous Language Source Code
Archive   : OPAL140.ZIP
Filename : RADIX.OPL

 
Output of file : RADIX.OPL contained in archive : OPAL140.ZIP

{
RADIX.OPL - Numeric Base Radix Conversion Example
OPAL - The Programmable DOS Shell
Copyright (c) 1986, The Software Factory, Inc.

This example OPAL program can be used to convert numbers to different bases.
Currently values up to base 16 (hex) are supported .

Only Base 10 (dec), Base 8 (oct), and Base 16 (hex) are printed out
}

scrclr
print("OPAL - Numeric Base Radix Conversion Utility%n%n")

let fldbar_ = '7m'
let flddsp_ = '1m'

let more=true
do while more
let value=conprompt(string_,15,"Enter a Value [cr to quit]: ")
if strlen(value)=0 then break
let radix=conprompt(integer_,2,"Enter Radix: ")
let base10=0
let count=0
do while strlen(value)<>0
let n=struc(strright(value,1))
select n
when "A"
let n="10"
when "B"
let n="11"
when "C"
let n="12"
when "D"
let n="13"
when "E"
let n="14"
when "F"
let n="15"
end
let n=strval(n)
let value=strleft(value,strlen(value)-1)
let base10=base10+(n*radix^count)
let count=count+1
end
let base10=strval(strfmt('%d',base10)) { Force rounded value }
print("Radix base %d Dec=%d Oct=%o Hex=%x%n",radix,base10,base10,base10)
end

end