May 2018
Beginner
332 pages
7h 28m
English
Integer values can be represented in decimal, binary, octal, or hex numeric notations. By default, integer values are represented in decimal notation. Binary numbers have base 2. Octal numbers use base 8. Hexadecimal numbers use base 16. We will learn about various notations with examples in this section.
This is the syntax:
variable=base#number-in-that-base
Let's understand the preceding syntax with examples:
$ declare -i x=21
$ echo $x
21
$ x=2#10101
$ echo $x
21
$ declare -i x
$ x=8#25
$ echo $x
21
$ declare -i x
$ x=16#15
$ echo $x
21
In the preceding examples, we displayed the decimal ...