Conversions, arithmetic operations, and complement methods with interactive tools
Grade XI • Computer Science ⏱️ ~35 minComputers understand binary (base 2). Humans use decimal (base 10), octal (base 8), and hexadecimal (base 16). Understanding how to convert between these is fundamental to computer science.
To convert decimal to binary, we repeatedly divide by 2 and record the remainders from bottom to top.
25 / 2 = 12 rem 1
12 / 2 = 6 rem 0
6 / 2 = 3 rem 0
3 / 2 = 1 rem 1
1 / 2 = 0 rem 1
Result: 11001₂
Each bit in a binary number has a weight of 2ⁿ. Sum the weights of all '1' bits.
| Bit | 1 | 0 | 1 | 1 |
|---|---|---|---|---|
| Weight | 2³=8 | 2²=4 | 2¹=2 | 2⁰=1 |
| Value | 8 | 0 | 2 | 1 |
Total: 8 + 0 + 2 + 1 = 11₁₀
Similar to binary conversion, but divide by 8. Use the powers of 8 table for reference.
| Power | 8³ | 8² | 8¹ | 8⁰ |
|---|---|---|---|---|
| Value | 512 | 64 | 8 | 1 |
173 / 8 = 21 rem 5
21 / 8 = 2 rem 5
2 / 8 = 0 rem 2
Result: 255₈
Divide by 16. Remember the mapping for remainders > 9:
10=A, 11=B, 12=C, 13=D, 14=E, 15=F
450 / 16 = 28 rem 2
28 / 16 = 1 rem 12 (C)
1 / 16 = 0 rem 1
Result: 1C2₁₆
Instead of going through decimal, use groupings:
Octal: 111 | 101 = 75₈
Hex: 0011 | 1101 = 3D₁₆
Test your ability to cross between multiple bases.
Step 1: 72₈ to Binary = 111 010₂
Step 2: 0011 1010₂ to Hex = 3A₁₆
Step 1: A5₁₆ to Binary = 1010 0101₂
Step 2: 010 100 101₂ to Octal = 245₈
When subtracting a larger bit from a smaller one (0-1), borrow 1 from the next higher column. The borrowed 1 acts as 2 in the current column (10 - 1 = 1).
1001 (9) - 0110 (6) ------- 0011 (3)
Similar to decimal multiplication. Multiply by each bit and sum the partial products.
101 x 11 ----- 101 (101 x 1) +1010 (101 x 10) ----- 1111 (15₁₀)
Use the long division method. It's actually easier than decimal because you only compare if the divisor goes in 0 or 1 times.
11 goes into 11 exactly 1 time.
Result: 100₂ (12 / 3 = 4)
Just flip every bit: 0 → 1 and 1 → 0.
Add the 1's complement of the subtrahend. If a carry is generated, add it to the LSB (End-around carry).
7 = 0111
3 = 0011 → 1's comp = 1100
Sum: 0111 + 1100 = (1)0011
End-around carry: 0011 + 1 = 0100 (4₁₀)
Add the 2's complement. Discard the final carry for positive results.
10 = 00001010
4 = 00000100 → 2's comp = 11111100
Sum: 00001010 + 11111100 = (1)00000110
Discard carry: 00000110 (6₁₀)
In signed 2's complement, the leftmost bit (MSB) is the sign bit (0 = positive, 1 = negative).
+13 = 00001101
1's comp = 11110010
2's comp = 11110011 (Result)
Test your speed and accuracy in the Number Systems Assessment.
Launch Assessment →