Number Systems: Binary, Octal, Decimal and Hexadecimal
A number system is a method for representing quantities using symbols and rules. Computer systems primarily use binary internally, while octal and hexadecimal provide compact ways to read and work with binary values.
1. Number-System Fundamentals
Every positional number system has a base, also called a
radix. The base tells us how many different digit symbols
may be used. In a base b system, valid digits have values from
0 through b − 1.
In a positional number system, a digit's value depends on both the digit itself and its position. Positions to the left of the radix point use positive powers of the base; positions to the right use negative powers.
| Number system | Base | Valid digits | Common use |
|---|---|---|---|
| Binary | 2 | 0, 1 | Digital circuits, memory, and machine-level representation |
| Octal | 8 | 0 to 7 | Compact representation of binary values in some contexts |
| Decimal | 10 | 0 to 9 | Everyday arithmetic and human-readable values |
| Hexadecimal | 16 | 0 to 9 and A to F | Memory addresses, colors, debugging, and compact binary notation |
Hexadecimal digit values
| Hexadecimal digit | Decimal value | Binary value |
|---|---|---|
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
2. Binary Terms and Digit Mappings
| Term | Meaning |
|---|---|
| Bit | A binary digit: either 0 or 1. |
| Nibble | A group of 4 bits. |
| Byte | A group of 8 bits. |
| Word | A processor-sized group of bits; its size depends on the computer architecture. |
| MSB | Most Significant Bit: the leftmost bit in a fixed binary representation. |
| LSB | Least Significant Bit: the rightmost bit in a fixed binary representation. |
Why octal and hexadecimal are useful
One octal digit represents exactly 3 binary bits because 23 = 8. One hexadecimal digit represents exactly 4 binary bits because 24 = 16.
| Octal | Binary | Octal | Binary |
|---|---|---|---|
| 0 | 000 | 4 | 100 |
| 1 | 001 | 5 | 101 |
| 2 | 010 | 6 | 110 |
| 3 | 011 | 7 | 111 |
3. Whole-Number Conversions
3.1 Convert any base to decimal
Multiply each digit by the power of the base associated with its position, then add the results.
Example: Convert (5AD)16 to decimal
5 × 162 + 10 × 161 + 13 × 160
= 5 × 256 + 10 × 16 + 13
= 145310
Example: Convert (125)8 to decimal
1 × 82 + 2 × 81 + 5 × 80
= 64 + 16 + 5 = 8510
3.2 Convert decimal to another base
For a whole decimal number, repeatedly divide by the target base. Record each remainder and read the remainders from bottom to top.
Example: Convert (156)10 to binary
156 ÷ 2 = 78 remainder 0
78 ÷ 2 = 39 remainder 0
39 ÷ 2 = 19 remainder 1
19 ÷ 2 = 9 remainder 1
9 ÷ 2 = 4 remainder 1
4 ÷ 2 = 2 remainder 0
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Therefore, (156)10 = (10011100)2
Example: Convert (1234)10 to hexadecimal
1234 ÷ 16 = 77 remainder 2
77 ÷ 16 = 4 remainder 13 (D)
4 ÷ 16 = 0 remainder 4
Therefore, (1234)10 = (4D2)16
3.3 Binary to octal and hexadecimal
To convert binary to octal, group bits in sets of 3 from the right. To convert binary to hexadecimal, group bits in sets of 4 from the right. Add leading zeros to the leftmost group when necessary.
Example: Convert (1010111100)2 to octal
001 010 111 100
(1010111100)2 = (1274)8
Example: Convert (1010101101001)2 to hexadecimal
0001 0101 0110 1001
(1010101101001)2 = (1569)16
3.4 Octal and hexadecimal conversion through binary
Binary is a convenient intermediate system because each octal digit maps to 3 bits and each hexadecimal digit maps to 4 bits.
Example: Convert (46)8 to hexadecimal
(46)8 = 100 1102
Add leading zeros and group into 4 bits: 0010 01102
Therefore, (46)8 = (26)16
4. Fractional Number Conversions
4.1 Convert a binary fraction to decimal
Digits after the radix point use negative powers of the base: 2-1, 2-2, 2-3, and so on.
Example: Convert (101101.101)2 to decimal
Whole part: 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 45
Fractional part: 1 × 2-1 + 0 × 2-2 + 1 × 2-3 = 0.625
Therefore, (101101.101)2 = (45.625)10
4.2 Convert a decimal fraction to binary
Repeatedly multiply the fractional part by 2. At each step, write down the integer part. Read the recorded integer parts from top to bottom.
Example: Convert (0.375)10 to binary
0.375 × 2 = 0.750 → 0
0.750 × 2 = 1.500 → 1
0.500 × 2 = 1.000 → 1
Therefore, (0.375)10 = (0.011)2
4.3 Convert a decimal fraction to octal
Use the same repeated-multiplication method, but multiply the fractional part by 8 instead of 2.
Example: Convert (0.375)10 to octal
0.375 × 8 = 3.000 → 3
Therefore, (0.375)10 = (0.3)8
A fraction terminates in base 2 only when its reduced denominator has no prime factors other than 2. This is why values such as 0.5, 0.25, and 0.375 terminate in binary, while 0.1 and 0.15 repeat.
5. Binary Arithmetic
5.1 Binary addition
| Operation | Sum bit | Carry out |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 0 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 | 1 | 1 |
1011
+ 0110
------
10001
Therefore, (1011)2 + (110)2 = (10001)2.
5.2 Binary subtraction
| Operation | Difference bit | Borrow |
|---|---|---|
| 0 − 0 | 0 | 0 |
| 1 − 0 | 1 | 0 |
| 1 − 1 | 0 | 0 |
| 0 − 1 | 1 | 1 |
10110
- 00111
-------
01111
Therefore, (10110)2 − (00111)2 = (01111)2.
5.3 Binary multiplication and shifts
Binary multiplication follows the same principle as decimal multiplication.
Multiplying an unsigned binary number by 102 shifts
all bits one place left, which is equivalent to multiplying by 2 when no
fixed-width overflow occurs.
1011₂ × 10₂ = 10110₂
11112 + 00012 = 100002.
In a 4-bit unsigned register, only 0000 fits and the extra
carry indicates overflow.
6. Signed Binary and Two's Complement
Computers need to represent negative as well as positive integers. The most common signed-integer representation is two's complement. In an n-bit two's-complement system, the range is:
−2n−1 to 2n−1 − 1
Finding the negative of a binary value
- Write the positive number using a fixed number of bits.
- Invert every bit.
- Add 1 to the inverted result.
Example: Represent −5 in 8-bit two's complement
+5 = 00000101
Invert bits = 11111010
Add 1 = 11111011
Therefore, 111110112 represents −5 in 8-bit two's complement.
The same bit pattern can have different meanings depending on whether it is
interpreted as unsigned or signed. For example,
111110112 is 251 as an 8-bit unsigned value but −5
as an 8-bit two's-complement value.
8. Quick Revision and Practice Questions
| Topic | Key point |
|---|---|
| Binary | Base 2; digits are 0 and 1. |
| Octal | Base 8; one octal digit corresponds to 3 binary bits. |
| Hexadecimal | Base 16; one hexadecimal digit corresponds to 4 binary bits. |
| Base-to-decimal conversion | Use positional powers of the base. |
| Decimal-to-base conversion | Use repeated division for whole numbers. |
| Fractional conversion | Use repeated multiplication by the target base. |
| Binary fraction | Positions after the radix point use negative powers of 2. |
| Two's complement | Invert the bits and add 1 to represent a negative value. |
| BCD | Encodes each decimal digit separately using binary. |
Practice questions
-
Convert (11110)2 to decimal.
Answer: 16 + 8 + 4 + 2 = (30)10. -
Convert (537)8 to binary.
Answer: 5 = 101, 3 = 011, and 7 = 111; therefore (537)8 = (101011111)2. -
Convert (CAFE)16 to decimal.
Answer: 12 × 163 + 10 × 162 + 15 × 16 + 14 = (51966)10. -
Why are octal and hexadecimal useful for binary values?
Answer: They provide shorter, easier-to-read groups of binary digits: 3 bits per octal digit and 4 bits per hexadecimal digit. -
What is the 8-bit two's-complement representation of −5?
Answer:11111011.