Lesson overview
Why computers use different number systems
Humans are comfortable with decimal because it uses ten digits from 0 to 9. Computers, however, work with binary, which uses only 0 and 1. Programmers also use hexadecimal as a compact way to write binary values. Understanding how to move between these systems is a basic but important skill in IT.
In this lesson, we focus on a concrete example from the module: converting decimal 25 to binary and hexadecimal. The same technique can be used for many other numbers.
Decimal and place value recap
In decimal, each position represents a power of ten. For example, in the number 25, the digit 2 means 2 tens, and the digit 5 means 5 ones, so:
25 = 2 × 10 + 5 × 1
Binary and hexadecimal follow the same idea, but use powers of 2 and 16 instead of powers of 10.
Converting decimal 25 to binary
Binary uses only the digits 0 and 1. Each place value is a power of 2 (1, 2, 4, 8, 16, and so on). One common method to convert decimal to binary is to divide repeatedly by 2 and record the remainders.
Step by step for 25:
- 25 ÷ 2 = 12, remainder 1
- 12 ÷ 2 = 6, remainder 0
- 6 ÷ 2 = 3, remainder 0
- 3 ÷ 2 = 1, remainder 1
- 1 ÷ 2 = 0, remainder 1
Now read the remainders from bottom to top:
1 1 0 0 1
So in binary:
25₁₀ = 11001₂
Checking using powers of two
We can check the answer by expanding 11001₂ using powers of 2:
- 1 × 16 (2⁴) = 16
- 1 × 8 (2³) = 8
- 0 × 4 (2²) = 0
- 0 × 2 (2¹) = 0
- 1 × 1 (2⁰) = 1
Add them: 16 + 8 + 1 = 25, so the binary conversion is correct.
Converting decimal 25 to hexadecimal
Hexadecimal, or hex, is base 16. It uses digits 0 to 9 and letters A to F to represent values 10 to 15. Hex is popular because one hex digit corresponds to four binary bits, which makes it a compact way to write binary numbers.
To convert decimal 25 to hex, we divide by 16 and record the quotient and remainder:
- 25 ÷ 16 = 1, remainder 9
The quotient is the sixteens place and the remainder is the ones place. This gives:
25₁₀ = 19₁₆
We can check again:
- 1 × 16 = 16
- 9 × 1 = 9
- 16 + 9 = 25
The result matches the original decimal value.
Summary of conversions for 25
Decimal: 25₁₀
Binary: 11001₂
Hexadecimal: 19₁₆
Decimal 25 → divide by 2 for binary → divide by 16 for hex → verify using place values.