Anonymous user
Non-decimal radices/Input: Difference between revisions
→{{header|J}}: header formats, note on numeric literals
(Added C#.) |
(→{{header|J}}: header formats, note on numeric literals) |
||
Line 241:
=={{header|J}}==
'''Solution 2''' (input sanitizing):<lang j>baseN=: 0&".@,&": 'b' , ] NB. Use if the source of the non-decimal "numbers" is not trustworthy</lang>
'''Example''':<lang j>
180154659
8 baseN '7651'
Line 251 ⟶ 249:
10 baseN '123459'
123459</lang>
'''Note''':
J also provides builtin support for numeric literals of an arbitrary base. The format is ''radix'''''b'''''digits'' (where ''radix'' is specified in base 10). The one restriction is that one cannot use digits larger than 36 ('z'):<lang j> 16babc123 8b7651 10b123459
11256099 4009 123459</lang>
▲<lang j>baseN=: 0&".@,&": 'b' , ]</lang>
=={{header|Java}}==
|