← Computer Science blog
Concept guide21 October 2026 · 4 min read

Number Systems: Binary, Octal, Hex Conversions and Two's Complement Made Easy

CSEITEEEENTCR&AIBCABSc CSBSc IT+4

Digital Electronics, Computer Organization and even Programming in C all start here. The conversions look like busywork until you notice they are just two repeated moves. Master those and you will never memorize another table.

Why four systems?

Computers use binary (base 2) because a wire is either on or off. Binary numbers are long and error-prone to read, so we group bits to write them compactly:

  • Octal (base 8): each digit is exactly 3 bits.
  • Hexadecimal (base 16): each digit is exactly 4 bits (0–9 then A–F).

Decimal to binary: divide by 2

Convert 45 to binary. Divide repeatedly by 2 and record the remainders, then read them bottom to top:

DivisionQuotientRemainder
45 ÷ 2221
22 ÷ 2110
11 ÷ 251
5 ÷ 221
2 ÷ 210
1 ÷ 201

Reading upward: 101101₂.

Check by expanding: 1×32 + 0×16 + 1×8 + 1×4 + 0×2 + 1×1 = 32 + 8 + 4 + 1 = 45 ✓

Binary to decimal: add the place values

Place values double from the right: 1, 2, 4, 8, 16, 32…

1101₂ = 8 + 4 + 0 + 1 = 13

Binary fractions: multiply by 2

Convert 0.625 to binary. Multiply the fraction by 2 repeatedly and take the integer part each time, reading top to bottom:

StepCalculationInteger part
10.625 × 2 = 1.251
20.25 × 2 = 0.50
30.5 × 2 = 1.01

So 0.625 = 0.101₂. (Check: ½ + ⅛ = 0.625 ✓.) Some fractions never terminate, such as 0.1, which is why floating-point numbers carry tiny errors.

Binary ⇄ octal ⇄ hex by grouping

No arithmetic needed, just group the bits.

Binary to hex: group in 4s from the right.

101101₂ → pad to 0010 1101 → 2 and D → 2D₁₆

Binary to octal: group in 3s from the right.

101101₂ → 101 101 → 5 and 5 → 55₈

Hex to binary: replace each digit with its 4 bits. 3F₁₆ = 0011 1111₂.

Check that 2D₁₆ is right: 2×16 + 13 = 45 ✓. And 55₈ = 5×8 + 5 = 45 ✓. All three represent the same number.

Negative numbers: why two's complement

Computers need to subtract, and building a separate subtractor circuit is wasteful. Two's complement lets the same adder do subtraction, because a negative number is stored in such a way that adding it behaves like subtracting.

How to get the two's complement (for n bits)

  1. Write the number in binary using n bits.
  2. Invert every bit (1's complement).
  3. Add 1.

Represent −5 in 8 bits:

+5      = 0000 0101
invert  = 1111 1010
add 1   = 1111 1011      →  −5

Subtraction becomes addition

Compute 7 − 5, which is 7 + (−5):

   0000 0111   (+7)
 + 1111 1011   (−5)
 -----------
 1 0000 0010

Discard the carry out of the leftmost bit. The result is 0000 0010 = +2 ✓.

Range of an n-bit two's complement number

−2^(n−1)  to  +2^(n−1) − 1

For 8 bits: −128 to +127. There is only one zero, and the leftmost bit works as the sign bit (0 positive, 1 negative). Notice the range is not symmetric: there is one more negative value than positive.

Overflow

If you add two numbers of the same sign and the result's sign differs (for example +100 + +100 in 8 bits gives a "negative" answer), overflow has occurred, because the true result (200) does not fit in the range. Overflow is detected when the carry into the sign bit differs from the carry out of it.

Exam checklist

  1. For decimal to binary, show the division table. Marks are for the working.
  2. For fractions, say clearly that the integer parts are read top to bottom.
  3. Always state how many bits you are using before writing two's complement.
  4. Verify by converting back, because it takes a minute and catches nearly all slips.

Sumantrak™ is an AI mentor built for Indian engineering, diploma, BCA and BSc CS/IT students — Digital Electronics, Computer Organization, and the rest of your syllabus, explained like this. Free to start →