Home › CSE Hub › Number Systems

Number Systems

Binary, octal, decimal and hexadecimal number systems, how to convert between them, and how computers store negative numbers using 1's and 2's complement.

हिंदी में: बाइनरी, ऑक्टल, डेसिमल और हेक्साडेसिमल — कंप्यूटर संख्याओं को कैसे समझता है।

Why number systems matter

Computers are built from switches that are either ON (1) or OFF (0), so they naturally work in binary. Programmers also use octal and hexadecimal because they are short, human-friendly ways to write long binary values.

System Base Digits used Example
Binary 2 0, 1 1011₂
Octal 8 0–7 13₈
Decimal 10 0–9 11₁₀
Hexadecimal 16 0–9, A–F B₁₆

In every positional system, the value of a digit = digit × baseposition, where the position starts at 0 from the right.

Decimal to binary

Divide the number by 2 repeatedly and write the remainders from bottom to top.

Example: 25₁₀

Division Quotient Remainder
25 ÷ 2 12 1
12 ÷ 2 6 0
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1

Reading the remainders upward: 25₁₀ = 11001₂.

Binary to decimal

Multiply each bit by its power of 2 and add.

11001₂ = 1×16 + 1×8 + 0×4 + 0×2 + 1×1 = 25₁₀

Binary ↔ octal and hexadecimal

  • Octal: group bits in 3s from the right. 11 001₂ → 011 001 → 3 1 → 31₈
  • Hexadecimal: group bits in 4s from the right. 1 1001₂ → 0001 1001 → 1 9 → 19₁₆
Decimal Binary Octal Hex
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Fractions

To convert a decimal fraction to binary, multiply by 2 repeatedly and take the integer parts from top to bottom. 0.625 × 2 = 1.25 → 1; 0.25 × 2 = 0.5 → 0; 0.5 × 2 = 1.0 → 1, so 0.625₁₀ = 0.101₂.

Negative numbers: 1’s and 2’s complement

Using 8 bits:

  • Sign-magnitude: the leftmost bit is the sign (0 = positive, 1 = negative). +5 = 00000101, −5 = 10000101. It has two zeros (+0 and −0).
  • 1’s complement: flip every bit. −5 = 11111010. Still two zeros.
  • 2’s complement: 1’s complement + 1. −5 = 11111011. Only one zero, and addition works directly — this is what almost all modern computers use.

An n-bit 2’s complement number ranges from −2n−1 to 2n−1 − 1. For 8 bits: −128 to +127.

Binary arithmetic

A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

Example: 0110 (6) + 0011 (3) = 1001 (9).

Codes you will meet

  • BCD (Binary Coded Decimal): each decimal digit is stored in 4 bits. 59 → 0101 1001.
  • ASCII: 7-bit code for English characters. ‘A’ = 65, ‘a’ = 97, ‘0’ = 48.
  • Unicode (UTF-8): encodes characters from all languages, including Hindi (Devanagari).
  • Gray code: only one bit changes between consecutive numbers; used in encoders.

Quick revision

  • Binary → octal: groups of 3 bits; binary → hex: groups of 4 bits.
  • 2’s complement = invert bits + 1.
  • 8-bit signed range: −128 to +127.
  • Hex digits A–F mean 10–15.