Number systems — solved exercises with the channels of a colour, opacities in binary, a 12-bit colour and a practice quiz (and the 256 that did not fit in 8 bits)
In the first practice midterm I did for this topic there was one of those questions you answer in five seconds: «What is the minimum number of bits needed to represent the number 256?». I thought: «2⁸ = 256, so 8», wrote it down and moved on. When I marked it: 9. With 8 bits there are 256 combinations, yes, but they go from 0 to 255. 256 is exactly the first one that no longer fits: 100000000, a 1 followed by eight zeros. Since then, every time I see a power of 2 in a range question, I stop to think whether they are asking how many numbers or which is the largest.
These are the exercises for the second paper topic of IC1. You already have the number systems theory (bases, weights, conversions and ranges) and the practice with four problems solved step by step. Now it is your turn, with the colours of the photos as always: the channels of a colour, some opacities in binary and a 24-bit colour reduced to 12. After that, three worked answers with a hidden mistake, the full solutions, a practice quiz and the cheat sheet.
Table of Contents
How to use this article
- Try each level on paper, without a calculator (there is none in the exam), with the method from the practice: data with their base, method, sums in order and check.
- If you get stuck, open the hint for that level. Just one.
- Before looking at the solutions, do «What’s wrong here?»: finding the mistake in someone else’s answer is exactly what helps you not to make it.
- Compare your working with the step-by-step solution, not just the final result, and finish with the quiz.
Level 1: the channels of a flower
In the same sunset photo there is a bougainvillea flower in the foreground. The eyedropper reads #C84B1F.
I ask you for:
- a) The decimal value of each channel (red C8, green 4B, blue 1F).
- b) Each channel in 8-bit binary.
- c) The whole colour in octal.
Expected result: a) 200, 75 and 31; b) 11001000, 01001011 and 00011111; c) .
For a), each channel is , with the letters replaced by their value. For b) there is no need to go through decimal: each hex digit is 4 bits. For c), put the 24 bits together and cut them in 3s from the right.
Level 2: opacities in binary
The editor stores the opacity of each layer in binary with 5 fractional digits. For these three layers:
- a) A shadow with opacity 0.8125.
- b) A gradient with opacity 0.6.
- c) A text layer with a font size of 13.6 points (this value is also stored with 5 fractional digits).
For each one, write the stored binary number, the decimal value it really represents and the error.
Expected result: a) 0.11010 = 0.8125, error 0; b) 0.10011 = 0.59375, error 0.00625; c) 1101.10011 = 13.59375, error 0.00625.
Before multiplying, ask yourself whether each fractional part is a sum of halves, quarters, eighths… One is and two are not. And in c), the integer part goes separately, with divisions.
Level 3 (challenge): a 12-bit colour
Some programs accept «short» colours of 3 hex digits, like #FA6: 4 bits per channel instead of 8. The screen shows them by repeating each digit: #FA6 is painted as #FFAA66.
I ask you for:
- a) How many different colours can be written with 3 hex digits? And with 6?
- b) Reduce the sky colour, #F4A261, to 3 digits by keeping the most significant digit of each channel.
- c) What decimal value does each channel of the short colour have as the screen paints it, and how much has it changed from 244, 162 and 97?
- d) Write the short colour in binary (12 bits) and in octal.
Expected result: a) 4096 and 16 777 216; b) #FA6; c) 255, 170 and 102 (+11, +8 and +5); d) 111110100110 and .
In c), FF, AA and 66 are converted to decimal like any two-digit hex number. Trick: repeating a hex digit d is the same as multiplying it by 17, because .
What’s wrong here?
Three answers from classmates, each with a mistake. Read the working, try to find the error before reading the explanation and think how you would fix it.
Snippet 1: the remainders in their order
A classmate converted the sky’s green, 162, to binary like this:
162 / 2 = 81 remainder 0 81 / 2 = 40 remainder 1 40 / 2 = 20 remainder 0 20 / 2 = 10 remainder 0 10 / 2 = 5 remainder 0 5 / 2 = 2 remainder 1 2 / 2 = 1 remainder 0 last quotient: 1 Result: 01000101
What’s wrong? The divisions are perfect, but the remainders are written from top to bottom with the last quotient at the end. 01000101 is 64 + 4 + 1 = 69, not 162. The first remainder is the least significant bit: you have to read from the last quotient upwards.
Reading the remainders in the order they come out. If you cannot remember which order it is, think of the first remainder: it says whether the number is even (0) or odd (1), so it is the units bit, the one on the right.
Fixed: last quotient and remainders from bottom to top: 10100010 = 128 + 32 + 2 = 162.
Snippet 2: the group left on the right
Another classmate had to convert to hexadecimal:
1011101 → groups of 4: 1011 | 101
1011 = B, 101 = 5
Result: B5
What’s wrong? She grouped from the left, so the incomplete group (101) ended up on the right, in the units position. But in a number the zeros that do not change the value are the ones on the left, not on the right.
Grouping from the left. B5 is 181, almost double the real value. Always group from the point (here, from the right) and pad the last group with zeros on the outside.
Fixed: from the right, 101 1101 → 0101 1101 = 5D. Check: and .
Snippet 3: ranges off by one
A third classmate answered two range questions like this:
a) Largest number with 3 hex digits: FFF = 16^3 = 4096 b) Minimum bits for the number 256: 2^8 = 256 → 8 bits
What’s wrong? Both have the same mistake: confusing the number of values () with the largest value (). In a), is how many numbers there are, from 000 to FFF; the largest, FFF, is 4095. In b), with 8 bits you reach 255, so 256 no longer fits.
Forgetting that 0 also counts. With m digits there are numbers, but they start at 0 and end at .
Fixed: a) 4095. b) : 9 bits.
Solutions
Level 1
Before any working, look at how the code is built: #C84B1F is read two digits at a time, C8 | 4B | 1F, and each pair is an 8-bit channel. Parts a) and b) are done channel by channel. Part c) is not: there the three channels become a single string of 24 bits.
a) Each channel to decimal (sum of weights with powers of 16, C = 12, B = 11, F = 15):
| Channel | Hex | Sum | Decimal |
|---|---|---|---|
| Red | C8 | 200 | |
| Green | 4B | 75 | |
| Blue | 1F | 31 |
Multiplying the wrong digit by 16: 8 × 16 + 12 = 140 instead of 200. The left-hand digit counts groups of 16, just as the 7 in 75 counts tens.
Lots of red, some green and hardly any blue: an intense orange-red, as a bougainvillea should be.
b) Each channel to binary. Each hex digit by its 4 bits, without going through decimal:
| Channel | Hex | Binary | Check |
|---|---|---|---|
| Red | C8 | 1100 1000 | 128 + 64 + 8 = 200 |
| Green | 4B | 0100 1011 | 64 + 8 + 2 + 1 = 75 |
| Blue | 1F | 0001 1111 | 16 + 8 + 4 + 2 + 1 = 31 |
What matters in this table are the leading zeros: the 4 in 4B is written 0100, not 100, and the 1 in 1F, 0001. For the value of a single channel they make no difference, but in c) the three channels are joined together and there position is everything.
Dropping those zeros. You are left with 20 bits instead of 24, everything shifts and the octal comes out as 3104577. If you do not get exactly 24 bits when you join the channels, a zero is missing somewhere.
c) The whole colour in octal. Put the 24 bits together and cut them in 3s from the right:
| Bits | 110 | 010 | 000 | 100 | 101 | 100 | 011 | 111 |
|---|---|---|---|---|---|---|---|---|
| Octal | 6 | 2 | 0 | 4 | 5 | 4 | 3 | 7 |
Why it is done this way: in b) going through decimal and dividing would work, but it is seven divisions per channel; groups of 4 bits are a table you already know. In c) you cannot convert channel by channel to octal (8 bits are not a multiple of 3): you have to put the 24 bits together first. That is why the octal of a colour cannot be read by channels, and why nobody writes colours in octal.
The tempting shortcut is to convert each channel to octal separately and stick the results together:
| Channel | Decimal | In octal | Why it does not work |
|---|---|---|---|
| Red | 200 | 310 | Its 8 bits do not split into groups of 3: it shares the third group with green. |
| Green | 75 | 113 | The same happens to it on both sides. |
| Blue | 31 | 37 | It gets the last two digits right by chance, but the group before them mixes one bit of green with two of blue. |
Stuck together it gives 31011337, not 62045437. Since 24 is a multiple of 3, the whole string splits into exactly 8 groups, with no padding.
Level 2
The plan before multiplying: multiplying a binary number by 2 moves the point one place to the right, so the digit that crosses into the integer part is the next fractional digit. That is why on each round you write down the integer part and carry on only with what is after the point.
And before the first round you already know which one ends: 0.8125 = 13/16 has a power of 2 underneath and terminates; 0.6 = 3/5 has a 5 and never terminates, so the 5 digits are a cut-off and the error appears.
a) 0.8125. Multiplications by 2:
| I multiply | Result | Digit |
|---|---|---|
| 0.8125 × 2 | 1.625 | 1 |
| 0.625 × 2 | 1.25 | 1 |
| 0.25 × 2 | 0.5 | 0 |
| 0.5 × 2 | 1.0 | 1 |
0 is left in the fourth round: 0.1101 exact. With 5 digits it is completed with a 0 on the right: 0.11010, which is 0.5 + 0.25 + 0.0625 = 0.8125. Error: 0. It was the one that is a sum of halves, quarters and sixteenths.
b) 0.6.
| I multiply | Result | Digit | Carry on with |
|---|---|---|---|
| 0.6 × 2 | 1.2 | 1 | 0.2 |
| 0.2 × 2 | 0.4 | 0 | 0.4 |
| 0.4 × 2 | 0.8 | 0 | 0.8 |
| 0.8 × 2 | 1.6 | 1 | 0.6 |
| 0.6 × 2 | 1.2 | 1 | 0.2 (it repeats) |
Digits from top to bottom: 0.10011. It is 0.5 + 0.0625 + 0.03125 = 0.59375. Error: 0.6 − 0.59375 = 0.00625, smaller than the weight of the last digit (), as it should be.
Here truncating and rounding give the same thing: the sixth digit would be a 0 (0.2 × 2 = 0.4). And the last row is the check: you are back to «carry on with 0.2», as after the first round, and from there the block 0011 repeats for ever.
Carrying on multiplying the whole result. If on the second round you do 1.2 × 2 = 2.4, you get a «digit» 2, which does not exist in binary: you forgot to remove the integer part.
c) 13.6. The integer part with divisions: 13 / 2 = 6 remainder 1; 6 / 2 = 3 remainder 0; 3 / 2 = 1 remainder 1; quotient 1 → 1101. The fractional part is the same 0.6 as in b): 10011. Together: 1101.10011, which is 13 + 0.59375 = 13.59375. Error: 0.00625, the same as in b), because the integer part adds no error.
Putting the whole 13.6 into the multiplications (13.6 × 2 = 27.2) or into the divisions (13.6 / 2 = 6.8). Divisions for the left of the point, multiplications for the right: split them before you start and join them at the end. The integer part adds no error because any integer is written exactly in binary (13 = 8 + 4 + 1).
Why it is done this way: in c) part b) is reused. In the exam, if two numbers share a fractional part, reusing the working is not cheating: it saves time and mistakes.
Level 3
a) 3 hex digits are 12 bits: 4096 colours. 6 digits are 24 bits: 16 777 216. Half the bits do not give half the colours but the square root: every bit you remove divides by two.
Why you multiply and do not add: each hex digit can take 16 values and each value of one combines with all the values of the others, so it is 16 × 16 × 16. Adding (16 + 16 + 16 = 48) counts digit values, not colours. Check of the square root: 4096 × 4096 = 16 777 216.
b) Keep the most significant digit of each channel: F4 → F, A2 → A, 61 → 6. Short colour: #FA6. Dropping the right-hand digit is dropping the 4 least significant bits of each channel.
In bits you can see why it is «dropping the 4 least significant bits»:
| Channel | Hex | 8 bits | Kept | Short digit |
|---|---|---|---|---|
| Red | F4 | 1111 0100 | 1111 | F |
| Green | A2 | 1010 0010 | 1010 | A |
| Blue | 61 | 0110 0001 | 0110 | 6 |
c) The screen paints #FFAA66:
| Channel | Original | Short (painted) | Decimal | Change |
|---|---|---|---|---|
| Red | F4 = 244 | FF | +11 | |
| Green | A2 = 162 | AA | +8 | |
| Blue | 61 = 97 | 66 | +5 |
All three channels go up a little: the short colour is slightly lighter and more saturated than the original. It looks alike, but it is not the same.
Cutting does not always give the closest short colour. A short channel can only show values in steps of 17 (0, 17… 238, 255), and 244 is 6 away from EE = 238 and 11 away from FF = 255. The exercise asks you to cut because it is the quick way. And all three channels go up because the repeated digit is bigger than the one removed; the rise is exactly the difference: 15 − 4 = 11, 10 − 2 = 8 and 6 − 1 = 5.
d) Each hex digit by its 4 bits: F = 1111, A = 1010, 6 = 0110 → 111110100110. In 3s from the right: 111 110 100 110 = . Check via decimal: and .
Why it is done this way: the trick of 17 in the hint () saves four sums of weights and explains why the «round» greys are 00, 11, 22… FF: they are multiples of 17. And in d), 12 bits is a multiple of 3 and of 4, so no padding is needed.
Practice quiz
Twenty questions to go over the whole topic: weights, conversions in the four bases, fractional parts, groups of bits and ranges. It does not count for anything (the IC1 exam is written, not multiple choice): it is there so you can see what you have clear and what you do not. You can repeat it as many times as you like; each answer comes with its explanation. In the boxes, write binary numbers without spaces.
What does it mean that the decimal system is positional?
- That the value of each digit depends on the position it occupies
- That the digits are always written in the same order
- That each number has a fixed position on the number line
- That only ten positions can be used
Solution
Answer: That the value of each digit depends on the position it occupies
In a positional system the number is a sum of digits multiplied by their weights, and the weight depends on the position: . Binary, octal and hexadecimal are positional too.
In the binary number , what is the weight of the position holding the 1?
- 0.25
- 0.01
- 0.5
- 2
Solution
Answer: 0.25
After the point the weights are negative powers of the base. In binary: , , … So .
Convert each number to decimal (sum of weights). Write only the decimal number.
| Number | Base | Value in decimal |
|---|---|---|
| 1100100 | 2 | |
| 144 | 8 | |
| 64 | 16 |
Solution
| Number | Base | Value in decimal |
|---|---|---|
| 1100100 | 2 | 100 |
| 144 | 8 | 100 |
| 64 | 16 | 100 |
All three are the same number. ; ; . That is why stating the base matters so much: «64» says nothing without it.
Convert (the green channel of the colour) to 8-bit unsigned binary. Write the 8 bits together.
Solution
Answer: 10100010
Successive divisions by 2: remainders 0, 1, 0, 0, 0, 1, 0 and last quotient 1. Read from bottom to top: 10100010. Check: .
True or false about base conversion:
- In successive divisions, the first remainder is the least significant bit.
- Decimal 0.1 can be written exactly in binary with enough bits.
- Decimal 0.75 is exactly 0.11 in binary.
- With m bits you can represent numbers up to .
Solution
- T — In successive divisions, the first remainder is the least significant bit.
- F — Decimal 0.1 can be written exactly in binary with enough bits.
- T — Decimal 0.75 is exactly 0.11 in binary.
- F — With m bits you can represent numbers up to .
The first remainder is the LSB, which is why they are read from bottom to top. 0.1 is periodic in binary (0.000110011…): it never ends, so there is always an error. , exact. With m bits the largest number is : with 8 bits, 255.
Put in order the steps to convert a decimal integer to binary by successive divisions:
- Check the result with the sum of weights
- Write the remainders after it in reverse order, back to the first one
- Take the last quotient as the most significant bit
- Repeat the division with the quotient while it can still be divided
- Divide the number by 2 and write down the quotient and the remainder
Solution
Correct order:
- Divide the number by 2 and write down the quotient and the remainder
- Repeat the division with the quotient while it can still be divided
- Take the last quotient as the most significant bit
- Write the remainders after it in reverse order, back to the first one
- Check the result with the sum of weights
The reading order is the key: last quotient and then the remainders from bottom to top. Checking with the sum of weights takes seconds and catches the most common mistake (reading them the wrong way round).
Fill in:
Each octal digit is a group of ____ bits, because , and each hexadecimal digit a group of ____ bits. To go from octal to hexadecimal you go through ____ first.
Words:
- 4
- binary
- 2
- decimal
- 8
- 3
Solution
Each octal digit is a group of 3 bits, because , and each hexadecimal digit a group of 4 bits. To go from octal to hexadecimal you go through binary first.
Since 8 and 16 are powers of 2, each digit is a fixed number of bits and the conversion is direct. There is no direct grouping between octal and hexadecimal (3 and 4 bits do not fit), so you go through binary and regroup.
Match each system with its digits:
| Binary | |
| Octal | |
| Decimal | |
| Hexadecimal |
Definitions:
- 0 to 9
- 0 to 7
- 0 to 9 and A to F
- 0 to 8
- 0 and 1
Solution
- Binary → 0 and 1
- Octal → 0 to 7
- Decimal → 0 to 9
- Hexadecimal → 0 to 9 and A to F
A base B has B digits, from 0 to . That is why there is no 8 in octal and hexadecimal needs six more symbols: A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Write in the other three bases (binary with 8 bits, no spaces).
| Base | Value |
|---|---|
| Binary | |
| Octal | |
| Hexadecimal |
Solution
| Base | Value |
|---|---|
| Binary | 11001000 |
| Octal | 310 |
| Hexadecimal | C8 |
, so in binary it is 11001000. In 4s: 1100 1000 = C8. In 3s from the right: 011 001 000 = 310.
What is in hexadecimal?
- 5D
- B5
- 5B
- D5
Solution
Answer: 5D
and . B5 is 181: almost double.
Convert to octal.
Solution
Answer: 257
Via binary: AF = 1010 1111. In 3s from the right: 010 101 111 = 2 5 7. Check: and .
You convert an opacity of 0.4 to binary with 4 fractional digits and get 0.0110. Which number is really being stored?
- 0.375
- 0.4
- 0.4375
- 0.25
Solution
Answer: 0.375
Cutting at a fixed number of digits stores a slightly smaller number: . The difference, 0.025, is the representation error.
Which of these decimal numbers can be written exactly in binary? (Tick all the correct ones)
- 0.5
- 0.625
- 0.8125
- 0.1
- 0.3
Solution
Answer: 0.5 · 0.625 · 0.8125
A fraction is exact in binary if it is a sum of halves, quarters, eighths, sixteenths… (its denominator is a power of 2). If multiplying by 2 brings back a value you have already seen, the number is periodic and never ends.
What is the minimum number of bits needed to write the number 300 in unsigned binary?
Solution
Answer: 9
and . With 8 bits you reach 255 (not enough); with 9, 511. 300 falls between 256 and 512: 9 bits.
What range of numbers can be represented with 3 hexadecimal digits?
- 0 to 4095
- 0 to 4096
- 0 to 999
- 0 to 48
Solution
Answer: 0 to 4095
With m digits in base B there are numbers, from 0 to . 3 hex digits are 12 bits: .
Convert to decimal.
Solution
Answer: 0.625
.
What is in decimal?
- 511
- 777
- 512
- 21
Solution
Answer: 511
777 in octal is 111 111 111 in binary: nine ones, . It is the largest number that fits in 3 octal digits.
True or false (look at the base of each number):
- is greater than
Solution
- T —
- T —
- T —
- F — is greater than
«10» in any base B is worth B, and «100» is worth . , less than 10: the same digits say nothing without the base.
A colour is stored with 24 bits (8 per channel). How many different colours can be stored?
- 16777216
- 16777215
- 768
- 256
Solution
Answer: 16777216
Each channel has values and they combine: colours, from #000000 to #FFFFFF.
The eyedropper picks the blue of the sea: #1E6F9C. Convert each channel to decimal.
| Channel | Hexadecimal | Decimal |
|---|---|---|
| Red | 1E | |
| Green | 6F | |
| Blue | 9C |
Solution
| Channel | Hexadecimal | Decimal |
|---|---|---|
| Red | 1E | 30 |
| Green | 6F | 111 |
| Blue | 9C | 156 |
; ; . Lots of blue, quite a lot of green and hardly any red: a light navy blue.
What next?
Number systems appear in everything left in IC1. If you want to see these ideas at work:
- In QtSpim everything is in hexadecimal: memory addresses (0x10010000), register contents and the data segment. Go over it in MIPS program structure and data, where each
.wordappears in hex in the dump. - In MIPS load, arithmetic and logic masks like
andi $t0, $t0, 0x0Fare groups of 4 bits: with this topic you can read them at a glance. - The strings in MIPS arrays and strings are bytes, and each byte, two hex digits.
- And when you want to test yourself with the full practical exam, there is the IC1 practical mock exam, which marks itself when you hand it in.
The next paper topic is binary arithmetic: adding and subtracting in binary and representing negative numbers with sign-magnitude and ones’ complement. Everything from today (weights, groups, ranges) is used there from the very first line.
To check your solutions, type the number into the One number, every form simulator: you will see each division and each multiplication by 2; its «Test yourself» section brings new numbers to convert.
Cheat sheet: number systems
The essentials in 30 seconds
- Value of a number = sum of each digit times its weight, ; after the point, negative weights.
- Base B: B digits, from 0 to . Hex: A = 10 … F = 15.
- With m digits: numbers, from 0 to .
- Decimal → binary: divisions (remainders from bottom to top) and multiplications (digits from top to bottom).
- 1 octal digit = 3 bits; 1 hex digit = 4 bits; group from the point, zeros on the outside.
I want to…
| I want to… | Method | Example |
|---|---|---|
| Convert from any base to decimal | Sum of weights | |
| Convert a decimal integer to base B | Successive divisions by B | 162 → 10100010 |
| Convert a decimal fraction to binary | Successive multiplications by 2 | 0.75 → 0.11 |
| Convert binary to octal or hex | Groups of 3 or 4 bits from the point | 11110100 → 364₈ / F4₁₆ |
| Convert between octal and hex | Via binary | 7531₈ → F59₁₆ |
| Know how many bits N needs | Smallest m with | 1000 → 10 bits |
| Know the representation error | Value asked for − value stored | 0.4 with 4 digits → 0.025 |
Powers and digits
| Value | Value | Hex | Binary | Octal | ||
|---|---|---|---|---|---|---|
| 1 | 0.5 | 0-7 | 0000-0111 | 0-7 | ||
| 16 | 0.25 | 8 | 1000 | 10 | ||
| 256 | 0.125 | A (10) | 1010 | 12 | ||
| 1024 | 0.0625 | C (12) | 1100 | 14 | ||
| 4096 | 0.03125 | F (15) | 1111 | 17 |
Templates
Successive divisions (integer part): N / B = quotient, remainder → repeat with the quotient until it is smaller than B → result = last quotient + remainders from bottom to top.
Successive multiplications (fractional part): f × 2 = integer part (digit) + rest → repeat with the rest until 0 or until the digits asked for → result = digits from top to bottom → error = f − stored value.
Grouping: outwards from the point, 3 bits (octal) or 4 bits (hex); padding with zeros on the left of the integer part and on the right of the fractional part.
Symptom / likely cause
| Symptom | Likely cause |
|---|---|
| The binary is worth a number that looks nothing like the starting decimal | Remainders read backwards |
| The fractional part comes out greater than 1 or very odd | Divided instead of multiplying |
| The hex or octal comes out almost double (or half) | Grouped from the left or padded on the inside |
| You get an 8 in octal or a «12» in a hex digit | Digit outside the base: in hex, 12 is C |
| The range ends at or at 4096 | Confused how many numbers with the largest |
| The representation error is larger than the weight of the last digit | One of the multiplication digits is wrong |
Before you hand it in, ask yourself
- Does each number carry its base?
- Have I written the number of bits they asked for, with zeros on the left?
- Have I checked each conversion by another route (sum of weights)?
- If there was a fractional part, have I given the stored value and the error?
Did this article help you? Here is how you can support SergioLearns →
Ready for the exam?IC1 practical mock exam — MIPS in QtSpim with other data, subroutines and keyboard input (and why part 1 decides almost everything)


