Literals/Integer: Difference between revisions

unix shell
(unix shell)
Line 127:
irb(main):003:0> 727 == 01327
=> true
</pre>
 
=={{header|UNIX Shell}}==
 
{{works with|bash}}
 
As manual states, 0x or 0X is the prefix for hexadecimal numbers, while 0 is the one for octal, and nothing means the number is decimal. But the sintax <tt>BASE#NUMBER</tt> can be used, with BASE going from 2 to 64, and the symbols used are digits, lowercase letters, uppercase letters, @ and _ <cite>in that order</cite>; <cite>if the BASE is less than or equal to 36, lowercase and uppercase letters can be used interchangeably to represent number from 10 and 35.</cite> (From the info manual of the Bash). This syntax works only in some circumstances, i.e. in the shell expansion (e.g. inside <tt>$(( ))</tt>) or using <tt>let</tt>.
 
<pre>
dec=727
oct=$(( 01327 ))
bin=$(( 2#1011010111 ))
hex=$(( 0x2d7 ))
# or e.g.
let bin=2#1011010111
let "baseXX = 20#1g7"
</pre>