- Advanced
- About 13 min
- 5 practice questions
Binary and decimal conversion
Convert whole numbers between binary and decimal with place values and repeated division, and check results by converting back.
If something looks wrong, please tell us.
Computers store everything as bits, each 0 or 1. The binary system has base 2, so each position is worth a power of 2 instead of a power of 10. Converting between binary and decimal is the foundation for every other number-system question.
Place values
| Position (from right, starting at 0) | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary to decimal
Add the place values wherever there is a 1. Take 1101: 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 8 + 4 + 0 + 1 = 13.
Decimal to binary
Divide repeatedly by 2 and note the remainders; the binary number is the remainders read from last to first. For 45: 45 / 2 = 22 remainder 1; 22 / 2 = 11 remainder 0; 11 / 2 = 5 remainder 1; 5 / 2 = 2 remainder 1; 2 / 2 = 1 remainder 0; 1 / 2 = 0 remainder 1. Reading upward gives 101101.
Worked example 1: check
Check 101101 by converting back: 32 + 0 + 8 + 4 + 0 + 1 = 45. Correct.
Worked example 2: how many values
With n bits there are 2 to the power n different patterns. With 8 bits: 2^8 = 256 patterns, representing 0 to 255. The largest n-bit unsigned number is 2^n - 1, so for 5 bits it is 32 - 1 = 31 (binary 11111).
Binary to decimal: add place values where the bit is 1. Decimal to binary: divide by 2 and read remainders upward.
Key takeaways
- Positions are powers of 2: 1, 2, 4, 8, 16, 32, 64, 128.
- n bits give 2^n patterns, maximum 2^n - 1.
- Always check by converting back.
Check your understanding
-
1. Convert binary 11011011 to decimal.
- 219
- 217
- 221
- 187
Show answer
Answer: A. Place values 128, 64, 32, 16, 8, 4, 2, 1 with digits 1, 1, 0, 1, 1, 0, 1, 1: 128 + 64 + 16 + 8 + 2 + 1 = 219.
-
2. Convert decimal 90 to binary.
- 1010110
- 1011010
- 1101010
- 101101
Show answer
Answer: B. 90 / 2 = 45 r0, 45 / 2 = 22 r1, 22 / 2 = 11 r0, 11 / 2 = 5 r1, 5 / 2 = 2 r1, 2 / 2 = 1 r0, 1 / 2 = 0 r1. Upward: 1011010. Check: 64 + 16 + 8 + 2 = 90.
-
3. What is the largest unsigned number that fits in 5 bits?
- 32
- 16
- 31
- 63
Show answer
Answer: C. 2^5 - 1 = 32 - 1 = 31, which is 11111.
-
4. How many different values can 10 bits represent?
- 1023
- 100
- 512
- 1024
Show answer
Answer: D. 2^10 = 1024. (1023 is the largest unsigned value.)
-
5. What is the range of unsigned numbers in 6 bits?
- 0 to 63
- 0 to 64
- 1 to 64
- 0 to 32
Show answer
Answer: A. 6 bits give 2^6 = 64 patterns, from 0 up to 64 - 1 = 63.
Sign in to keep track of the lessons you finish.