OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Number Bases

Back in Chapter 9, we got a look at octal (base 8) and hexadecimal (base 16) numbers. In arithmetic expressions, the shell supports integer constants in any base.


Table 34-2: Specifying Different Number Bases


Notation Description

Notation Description

number By default, numbers without any notation are treated as decimal (base 10) integers.


image

0number In arithmetic expressions, numbers with a leading zero are considered octal.


image

0xnumber Hexadecimal notation


image

base#number number is in base


image


Some examples:



[me@linuxbox ~]$ echo $((0xff))

255

[me@linuxbox ~]$ echo $((2#11111111))

255

[me@linuxbox ~]$ echo $((0xff))

255

[me@linuxbox ~]$ echo $((2#11111111))

255


In the examples above, we print the value of the hexadecimal number ff (the largest two-digit number) and the largest eight-digit binary (base 2) number.


Top OS Cloud Computing at OnWorks: