Binary, Octal, and Hexadecimal Number Systems
This article explains positional notation across different numerical bases: binary (base-2), octal (base-8), decimal (base-10), and hexadecimal (base-16).
Positional Notation
In a positional number system, the numerical value of a digit depends on its position within the number string.
For example, decimal number 345 evaluates to:
$$345 = 3 \times 10^2 + 4 \times 10^1 + 5 \times 10^0 = 300 + 40 + 5$$
Each position to the left represents a value multiplied by the base $B = 10$.
For any base $B$, a number with digits $d_n d_{n-1} \ldots d_1 d_0$ evaluates according to the formula:
$$\text{Value} = \sum_{i=0}^{n} d_i \cdot B^i$$
In binary, $B = 2$. In hexadecimal, $B = 16$. The mathematical structure remains identical across all positional number systems.
Binary Representation (Base-2)
In base-2, the base is $B = 2$ and the only valid digits are 0 and 1. The column weights correspond to powers of two:
$$\ldots 2^5,\ 2^4,\ 2^3,\ 2^2,\ 2^1,\ 2^0 = \ldots 32,\ 16,\ 8,\ 4,\ 2,\ 1$$
Figure 1 shows the evaluation of binary value $101101_2$ by summing active column weights.
$$1 \times 32 + 0 \times 16 + 1 \times 8 + 1 \times 4 + 0 \times 2 + 1 \times 1 = 45_{10}$$
In C, Python, and Verilog, designers designate binary literals using the prefix 0b (for example, 0b101101).
Powers of Two Reference
Digital systems frequently utilize standard powers of two:
| Power of 2 | Decimal Value | Standard Identifier |
|---|---|---|
| $2^0$ | 1 | Unit |
| $2^1$ | 2 | Pair |
| $2^2$ | 4 | Nibble lower half |
| $2^3$ | 8 | Byte half |
| $2^4$ | 16 | Nibble |
| $2^5$ | 32 | Word boundary |
| $2^6$ | 64 | Cache line size |
| $2^7$ | 128 | 7-bit ASCII range |
| $2^8$ | 256 | 8-bit Byte range |
| $2^{10}$ | 1,024 | 1 Kibi (Ki / 1K) |
| $2^{16}$ | 65,536 | 64 Kibi (64K) |
| $2^{20}$ | 1,048,576 | 1 Mebi (Mi / 1M) |
| $2^{30}$ | 1,073,741,824 | 1 Gibi (Gi / 1G) |
Hexadecimal Representation (Base-16)
Binary values require long strings of digits. Hexadecimal (base-16) provides a compact representation.
Base-16 uses 16 digit symbols: digits 0 through 9 represent values 0 through 9, and letters A through F represent values 10 through 15.
| Hexadecimal | Decimal | Binary (4-bit) |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Because $16 = 2^4$, exactly four binary bits map to one hexadecimal character. You can convert between binary and hexadecimal through direct 4-bit substitution without arithmetic division.
For example, the 32-bit binary address 11001010111100001111111000000001 converts directly to 0xCAF0FE01.
Octal Representation (Base-8)
Octal uses base $B = 8$ with digits 0 through 7. Because $8 = 2^3$, one octal digit represents exactly three binary bits.
In Unix operating systems, file permissions use octal notation:
rwxr-xr-x
111 101 101 (binary)
7 5 5 (octal)
In command chmod 755 script.sh, read equals 4 ($2^2$), write equals 2 ($2^1$), and execute equals 1 ($2^0$). The owner permission evaluates to $4 + 2 + 1 = 7$. Group and other permissions evaluate to $4 + 0 + 1 = 5$.
Note: In C, an integer literal beginning with a leading zero represents an octal number (for example, 010 evaluates to 8).
Numerical Equivalents: 0 through 31
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 00000 | 00 | 00 |
| 1 | 00001 | 01 | 01 |
| 2 | 00010 | 02 | 02 |
| 3 | 00011 | 03 | 03 |
| 4 | 00100 | 04 | 04 |
| 5 | 00101 | 05 | 05 |
| 6 | 00110 | 06 | 06 |
| 7 | 00111 | 07 | 07 |
| 8 | 01000 | 10 | 08 |
| 9 | 01001 | 11 | 09 |
| 10 | 01010 | 12 | 0A |
| 11 | 01011 | 13 | 0B |
| 12 | 01100 | 14 | 0C |
| 13 | 01101 | 15 | 0D |
| 14 | 01110 | 16 | 0E |
| 15 | 01111 | 17 | 0F |
| 16 | 10000 | 20 | 10 |
| 17 | 10001 | 21 | 11 |
| 18 | 10010 | 22 | 12 |
| 19 | 10011 | 23 | 13 |
| 20 | 10100 | 24 | 14 |
| 21 | 10101 | 25 | 15 |
| 22 | 10110 | 26 | 16 |
| 23 | 10111 | 27 | 17 |
| 24 | 11000 | 30 | 18 |
| 25 | 11001 | 31 | 19 |
| 26 | 11010 | 32 | 1A |
| 27 | 11011 | 33 | 1B |
| 28 | 11100 | 34 | 1C |
| 29 | 11101 | 35 | 1D |
| 30 | 11110 | 36 | 1E |
| 31 | 11111 | 37 | 1F |
Conversion Examples
Binary to Decimal Conversion
Convert $10110011_2$ to decimal. Multiply each bit by its positional column weight:
| Bit Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Column Weight | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit Value | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
$$\text{Value} = 128 + 32 + 16 + 2 + 1 = 179_{10}$$
Hexadecimal to Decimal Conversion
Convert 0xB4 to decimal. Character B equals 11:
$$\text{Value} = 11 \times 16^1 + 4 \times 16^0 = 176 + 4 = 180_{10}$$
Hexadecimal to Binary Conversion
Convert 0x3A7F to binary. Replace each hexadecimal character with its 4-bit binary equivalent:
$$\mathtt{3} = 0011_2,\quad \mathtt{A} = 1010_2,\quad \mathtt{7} = 0111_2,\quad \mathtt{F} = 1111_2$$
Result: $0011,1010,0111,1111_2$
Practice Exercises
- Convert binary value $11010110_2$ to decimal and hexadecimal.
- Convert hexadecimal value
0x2Fto binary and decimal. - Determine the binary representation and file access permissions for
chmod 640.
View Solutions
- Binary to decimal: $128 + 64 + 16 + 4 + 2 = 214_{10}$. In hexadecimal, group bits in fours (
1101 0110):0xD6. - Hexadecimal
0x2Fequals binary0010 1111. In decimal: $2 \times 16 + 15 = 47_{10}$. - Octal 640 equals binary
110 100 000. The file owner has read and write permissions (6). Group members have read permission (4). Other users have no access permissions (0).