tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,39 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
import java.math.BigInteger
|
||||
|
||||
numeric digits 200
|
||||
|
||||
parse arg input -- input should be val, radix; no input results in using default test data
|
||||
-- test data - number pairs where 1st is value and 2nd is target radix
|
||||
inputs = [ -
|
||||
'1234, 10', '01234, 8', 'fe, 16', 'f0e, 16', -
|
||||
'0, 10', '00, 2', '11, 2', '070, 8', -
|
||||
'77, 8', 'f0e, 16', '070, 16', '0xf0e, 36', -
|
||||
'000999ABCXYZ, 36', 'ff, 36', 'f, 16', 'z, 37' -
|
||||
]
|
||||
if input.length() > 0 then inputs = [input] -- replace test data with user input
|
||||
|
||||
loop i_ = 0 to inputs.length - 1
|
||||
do
|
||||
in = inputs[i_]
|
||||
parse in val . ',' radix .
|
||||
valB = toDecimal(val, radix) -- NetRexx default is to store digits as Rexx strings
|
||||
valD = fromDecimal(valB + 0, radix) -- Add zero just to prove the result treated as a number
|
||||
say val.right(16)'['radix.right(2, 0)']:' valB.right(16)'[10] ==' valD.right(16)'['radix.right(2, 0)']'
|
||||
catch nx = NumberFormatException
|
||||
say 'Error -- Input:' val', radix:' radix
|
||||
nx.printStackTrace()
|
||||
end
|
||||
end i_
|
||||
|
||||
return
|
||||
|
||||
method toDecimal(val = String, radix = int 10) public static returns Rexx
|
||||
bi = BigInteger(val, radix)
|
||||
return bi.toString()
|
||||
|
||||
method fromDecimal(val = String, radix = int 10) public static returns Rexx
|
||||
bi = BigInteger(val.toString(), 10)
|
||||
return bi.toString(radix)
|
||||
Loading…
Add table
Add a link
Reference in a new issue