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.

General rule: In (dn...d1d0.d-1d-2)b, each digit is multiplied by its corresponding power of b.
Common positional number systems
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

Letters used in hexadecimal notation
Hexadecimal digit Decimal value Binary value
A101010
B111011
C121100
D131101
E141110
F151111

2. Binary Terms and Digit Mappings

Important binary terms
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-to-binary mapping
Octal Binary Octal Binary
00004100
10015101
20106110
30117111

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

Important: Many decimal fractions do not terminate in binary. For example, 0.1510 is 0.001001100110011...2. In practice, a computer must store a rounded approximation when the available number of bits is limited.

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

Binary addition rules
Operation Sum bit Carry out
0 + 000
0 + 110
1 + 010
1 + 101
1 + 1 + 111
   1011
 + 0110
 ------
  10001

Therefore, (1011)2 + (110)2 = (10001)2.

5.2 Binary subtraction

Binary subtraction rules
Operation Difference bit Borrow
0 − 000
1 − 010
1 − 100
0 − 111
   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₂
Carry and overflow are not identical. For example, 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

  1. Write the positive number using a fixed number of bits.
  2. Invert every bit.
  3. 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

Number-system quick-revision table
Topic Key point
BinaryBase 2; digits are 0 and 1.
OctalBase 8; one octal digit corresponds to 3 binary bits.
HexadecimalBase 16; one hexadecimal digit corresponds to 4 binary bits.
Base-to-decimal conversionUse positional powers of the base.
Decimal-to-base conversionUse repeated division for whole numbers.
Fractional conversionUse repeated multiplication by the target base.
Binary fractionPositions after the radix point use negative powers of 2.
Two's complementInvert the bits and add 1 to represent a negative value.
BCDEncodes each decimal digit separately using binary.

Practice questions

  1. Convert (11110)2 to decimal.
    Answer: 16 + 8 + 4 + 2 = (30)10.
  2. Convert (537)8 to binary.
    Answer: 5 = 101, 3 = 011, and 7 = 111; therefore (537)8 = (101011111)2.
  3. Convert (CAFE)16 to decimal.
    Answer: 12 × 163 + 10 × 162 + 15 × 16 + 14 = (51966)10.
  4. 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.
  5. What is the 8-bit two's-complement representation of −5?
    Answer: 11111011.