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 1''':<lang j>baseN=: 0&".@(,&": 'b' &, ])&.":</lang>
This will satisfy the requirements:
'''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>baseN=: (, 16 baseN 'babcf123'&,)&.":
 
16 baseN 'abcf123'
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
That said, if the source of the non-decimal "numbers" is not trustworthy, the following should be used instead:
11256099 4009 123459</lang>
 
<lang j>baseN=: 0&".@,&": 'b' , ]</lang>
 
=={{header|Java}}==
Anonymous user