Number systems — practice with guided problems step by step: from any base to decimal, binary with a point, groups of bits and a question in the exam format (and the fraction I divided as if it were an integer)
In the first IC1 mock exam I did at home I had to convert 25.75 to binary. I got the integer part right: divisions of 25, 11001. And for the fractional part I thought: «same thing with the 75». Divisions of 75 by 2, remainders from bottom to top, 1001011. Result: 11001.1001011. I checked it with the sum of weights… only the integer part, of course. When I marked it I saw the solution: 11001.11. 0.75 is not «seventy-five» sitting after a point: it is three quarters, and three quarters in binary is a half plus a quarter, 0.11. Since then, before touching a fractional part I ask myself: «is this a number or a piece of one?».
This is the practice for the second paper topic of IC1. In the number systems theory we saw what a positional system is, binary, octal and hexadecimal, and how to convert from one base to another, always with the colour of the sunset photo (#F4A261). Here we solve four problems step by step, the way they are done in the written exam: the result is not enough, you have to show the way. For each one you will see the method, the reason for each step, how to check it and the mistakes that come up most. The data still comes from the phone’s photo editor.
Table of Contents
Before you start
It helps to be clear about:
- The formula of a positional system: each digit times its weight, , with negative weights after the point.
- The powers of 2 by heart, from to , and those of 8 and 16 up to 4096.
- What is read from bottom to top (the remainders of the divisions) and what from top to bottom (the digits of the multiplications).
- The table from 0 to 15 in binary, octal and hexadecimal.
If any of them sounds shaky, go over the theory before carrying on.
There is no calculator in the exam, and this topic is designed to be done by hand. Write the row of powers of 2 in a corner of the sheet when you start: it saves you mistakes in every question, not just this one.
How to solve a paper problem
The four problems follow the same four-step method. I give it here once so as not to repeat it:
- Write down the data with their base and underline what you are asked for (in which base, with how many digits).
- Choose the method before calculating: sum of weights, divisions, multiplications or grouping bits? The conversion map in the theory tells you.
- Solve in order, showing each step. In the written exam, a result without working is worth little, and good working with a slip at the end is worth almost everything.
- Check with another method: if you went from decimal to binary with divisions, come back with the sum of weights; if you grouped bits, convert both results to decimal.
Problem 1: from any base to decimal
Statement. The photo editor saves its settings in a text file and, for reasons of its own, each setting appears in a different base. Convert to decimal:
- a) The crop:
- b) The rotation:
- c) The sharpness:
The idea
All three are the same problem: sum of weights. The only thing that changes is the base of the powers. The method: write above each digit its weight, starting with just to the left of the point (it goes up to the left and down to the right), and add digit × weight. In hexadecimal, before multiplying, each letter is replaced by its value (B = 11).
Before calculating, think about the order of magnitude. In part c), 3B has three «sixteens»: the result should be around 50 or 60. If you get 500, something is wrong.
Step by step
a) In binary you only add the weights of the 1s:
| Digit | 1 | 0 | 1 | 1 | 0 | . | 1 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|---|
| Weight | 16 | 8 | 4 | 2 | 1 | 0.5 | 0.25 | 0.125 |
b) In octal the weights are powers of 8, and now you do have to multiply each digit:
The last term is the one people get wrong most: and . If you do it as a fraction, , it is harder to slip.
The same calculation, row by row. Weights are numbered from the point: the 7 is right to its left, so it is position 0.
| Digit | Position | Weight | Digit × weight | Why |
|---|---|---|---|---|
| 2 | 2 | 8 · 8 = 64 | 128 | Two places to the left of the units |
| 5 | 1 | 8 | 40 | The «eights» place, like the tens place in decimal |
| 7 | 0 | 1 | 7 | The units, right next to the point |
| 6 | −1 | 1/8 = 0.125 | 0.75 | The first one after the point: an eighth of a unit |
Sum: 128 + 40 + 7 + 0.75 = 175.75.
c) In hexadecimal, B = 11 and the weights are powers of 16:
With .
Check
An independent check: convert all three to binary and see that the sum of weights gives the same.
- b) = 010 101 111 . 110 = 10101111.11 = 128 + 32 + 8 + 4 + 2 + 1 + 0.5 + 0.25 = 175.75.
- c) = 0011 1011 . 0100 = 111011.01 = 32 + 16 + 8 + 2 + 1 + 0.25 = 59.25.
Same result by two different routes. And the order of magnitude fits: 59 is between 48 (hex 30) and 64 (hex 40).
Questions you might ask
Why is the weight of the first digit after the point and not ? Because already belongs to the units position, just to the left of the point. After the point starts what is less than one unit: halves in binary, eighths in octal, sixteenths in hex.
Do I have to write the terms that are 0? In binary there is no need (they are ignored), but in the exam it is worth showing the full table of weights: that way the marker sees you know the weight of each position.
What if a hex letter is after the point? The same: replace it by its value and multiply by its weight. .
How many decimal places will the result have? A binary number with n fractional digits always gives at most n decimal places (1/2, 1/4, 1/8… end in 5). That is why converting to decimal is always exact; the error only appears when converting from decimal.
Numbering the weights from the left of the number. With 10110.101, if you give the first 1 the weight instead of , the whole number comes out doubled.
Try it yourself
- Convert to decimal , and . Hint: all three have the same fractional part.
- What is worth in any base B? Write it for B = 2, 8 and 16.
Problem 2: a number with a point to binary, and its error
Statement. In the editor you raise the photo’s brightness by 45.3 %. The program stores that value in binary with 6 fractional digits. a) What binary number does it store? b) What decimal value is it really storing? c) What error does it make?
The idea
A number with integer and fractional parts is split in two and each half is done with its own method: successive divisions for 45 and successive multiplications for 0.3. Then they are joined with the point. Since the statement fixes 6 fractional digits, the multiplications stop at the sixth even if they have not finished: that is where the error comes from.
Before you start, ask yourself whether 0.3 is a sum of halves, quarters, eighths… It is not (it is 3/10, and 10 is not a power of 2), so you already know there will be an error.
Step by step
Integer part, 45. Divisions by 2:
Fractional part, 0.3. Multiplications by 2, six times:
| Round | I multiply | Result | Digit | Carry on with |
|---|---|---|---|---|
| 1 | 0.3 × 2 | 0.6 | 0 | 0.6 |
| 2 | 0.6 × 2 | 1.2 | 1 | 0.2 |
| 3 | 0.2 × 2 | 0.4 | 0 | 0.4 |
| 4 | 0.4 × 2 | 0.8 | 0 | 0.8 |
| 5 | 0.8 × 2 | 1.6 | 1 | 0.6 |
| 6 | 0.6 × 2 | 1.2 | 1 | 0.2 (not finished) |
Digits from top to bottom: 010011.
Why is the integer part of each result a digit, and why are they read from top to bottom? Multiplying by 2 moves the point one place in binary, so the digit that was right after the point (the one with weight 1/2) crosses over to the integer side. In round 1, 0.3 × 2 = 0.6 does not reach 1: 0.3 is less than half a unit, and the first digit is 0. In round 2 you get 1.2: what was left does contain a quarter, and the second digit is 1. The first digit that comes out is the one with the most weight after the point, which is why they are read in the order they come out, the opposite of the remainders of the divisions.
a) Joining them: .
b) What is really stored, with the sum of weights of the fractional part:
Slowly, digit by digit:
| Digit | Position | Weight | Adds | Why |
|---|---|---|---|---|
| 0 | −1 | 1/2 = 0.5 | 0 | A 0 adds nothing |
| 1 | −2 | 1/4 = 0.25 | 0.25 | Each weight is half of the previous one |
| 0 | −3 | 1/8 = 0.125 | 0 | Half of 0.25; with a 0, it adds nothing |
| 0 | −4 | 1/16 = 0.0625 | 0 | Half of 0.125; it adds nothing either |
| 1 | −5 | 1/32 = 0.03125 | 0.03125 | Half of 0.0625 |
| 1 | −6 | 1/64 = 0.015625 | 0.015625 | Half of 0.03125 |
Only the weights of the 1s add up: 0.25 + 0.03125 + 0.015625 = 0.296875.
So the stored value is 45.296875.
c) The error is what has been lost:
Check
Two quick checks:
- The integer part, with the sum of weights: 101101 = 32 + 8 + 4 + 1 = 45.
- The error must be smaller than the weight of the last digit: with 6 digits, , and 0.003125 is smaller. If you got an error larger than that weight, some digit would be wrong.
Notice also that in round 6 you get 0.2 again, which already came out in round 2: from there on the digits would repeat (0011 0011…). 0.3 is periodic in binary.
Questions you might ask
Why does the integer part never have an error? Because any integer is a finite sum of powers of 2: the divisions always end. The error can only come from cutting a periodic fractional part.
Is the last digit rounded? In this topic, no: the course notes cut (truncate) at the number of digits asked for, and the error is computed with what is left. If the statement asked for rounding, it would say so.
How many digits would be needed for the error to be smaller than 0.001? The truncation error is always smaller than the weight of the last stored digit, so it is enough that : with n = 10, .
What if they ask for the result in hexadecimal? Group the binary from the point: 0010 1101 . 0100 1100 = 2D.4C. Careful: the fractional part 010011 has 6 bits and must be completed to 8 with zeros on the right: 0100 1100.
Doing the fractional part with divisions, as if 0.3 were «the 3». You would get 0.11, which is 0.75: a huge error. What comes after the point is multiplied.
What would happen if you did the 0.75 from my mock exam with divisions, like I did?
Dividing 75 by 2 gives the remainders 1, 1, 0, 1, 0, 0, 1; read from bottom to top, 1001011. That is 75 in binary, not 0.75.
If you put those digits after the point, 0.1001011 is worth 0.5 + 0.0625 + 0.015625 + 0.0078125 = 0.5859375. You have lost 0.75 − 0.5859375 = 0.1640625 along the way, more than a fifth of what you wanted to store.
With the right method it takes two rounds:
| Round | I multiply | Result | Digit | Why |
|---|---|---|---|---|
| 1 | 0.75 × 2 | 1.5 | 1 | 0.75 does contain half a unit |
| 2 | 0.5 × 2 | 1.0 | 1 | What is left, 0.25, is exactly a quarter |
It reaches 0 and stops: 0.75 = 0.11, exactly. So 25.75 = 11001.11, as the solution said.
Try it yourself
- Convert 12.8 to binary with 5 fractional digits. What value is stored and what is the error?
- Repeat the problem with 45.375. Why is the error 0 now?
Problem 3: between binary, octal and hexadecimal
Statement. With the eyedropper you now tap the sea in the same photo and get the colour #1E6F9C.
- a) Write it in binary (24 bits) and in octal.
- b) An old manual shows a file permission written in octal, . Convert it to hexadecimal.
- c) Convert to octal and to hexadecimal.
The idea
None of the three needs a single division: it is all grouping bits. Hex ↔ binary with groups of 4, octal ↔ binary with groups of 3, and between octal and hex you go through binary. The two rules that decide the mark: group outwards from the point, and the padding zeros go on the outside (left of the integer part, right of the fractional part).
Step by step
a) Each hex digit by its 4 bits:
| Hex | 1 | E | 6 | F | 9 | C |
|---|---|---|---|---|---|---|
| Bits | 0001 | 1110 | 0110 | 1111 | 1001 | 1100 |
Now in 3s from the right (24 bits = exactly 8 groups):
| Bits | 000 | 111 | 100 | 110 | 111 | 110 | 011 | 100 |
|---|---|---|---|---|---|---|---|---|
| Octal | 0 | 7 | 4 | 6 | 7 | 6 | 3 | 4 |
The first group, 000, gives a 0 on the left that is worth nothing and can be dropped.
b) From octal to binary, each digit by its 3 bits, then regroup in 4s from the right:
12 bits: 4 groups of 3 or 3 groups of 4, no padding.
The same conversion, step by step:
| Step | What you do | Result | Why |
|---|---|---|---|
| 1 | 7 → 111, 5 → 101, 3 → 011, 1 → 001 | 111 101 011 001 | Each octal digit is exactly 3 bits |
| 2 | Join the bits | 111101011001 | It is the same number written in binary |
| 3 | Cut in 4s from the right | 1111 0101 1001 | Each hexadecimal digit is 4 bits, and you group from the point (here, the end) |
| 4 | 1111 → F, 0101 → 5, 1001 → 9 | F59 | 1111 = 15 = F; 0101 = 5; 1001 = 9 |
In between, the binary does not change: only where you cut it changes.
c) Here the point appears. Group on both sides of the point, outwards:
- Octal: integer part 1011 → 001 011 (two padding zeros on the left) = 13; fractional part 01 → 010 (one zero on the right) = 2. Result: .
- Hexadecimal: integer part 1011 = B; fractional part 01 → 0100 (two zeros on the right) = 4. Result: .
Check
Convert everything to decimal with the sum of weights:
- a) , , : a blue with a fair amount of green and little red, the colour of the sea. And in decimal is , which is also (if you feel like checking it, the Python program at the end does).
- b) and .
- c) ; ; .
Questions you might ask
Why do you pad on the right in the fractional part? For the same reason you pad on the left in the integer part: on the outside, where a 0 does not change the value. 0.01 and 0.010 are worth the same; 0.01 and 0.001 are not.
What happens if I pad on the wrong side in the fractional part? 0.01 becomes 0.001 = 0.125 instead of 0.25. In octal you would get 13.1 instead of 13.2: the value changes.
Can I go straight from octal to hexadecimal without writing the binary? With practice, in your head; in the exam, better to write it: it is one more line and it is where your reasoning shows.
Why does the colour’s octal start with 0? Because 24 bits are 8 groups of 3 and the first one is 000. Just as , that 0 can be dropped.
Grouping from left to right. With 1011.01 in octal you would get 101 1 . 01, which are not even complete groups. From the point, always.
Try it yourself
- Convert the colour #F4A261 (the sky) to binary and to octal without looking at the theory. Do you get 75121141 in octal?
- Convert (the 75 % opacity) to octal and to hexadecimal. Why is it not 0.3 in hex?
Problem 4: a question in the exam format
In the IC1 theory exam (2 hours, 7-9 questions adding up to 11 marks out of 10) each question shows its marks and some boxes where the answer goes, and the working is handed in on separate sheets. Without working the answer is not marked, and no calculator is allowed. The first question usually asks you to translate numbers given in base 10, 16 and 8 into 8-bit binary before operating with them (the operations belong to the next topics). This question is original and written in that format, so you can practice answering quickly and well.
Question (1 mark). a) Translate the numbers , and into 8-bit unsigned binary [0.6 marks]. b) What is the minimum number of bits needed to represent in unsigned binary? [0.2 marks] c) What is the largest number, in decimal, that can be written with 3 hexadecimal digits? [0.2 marks]
| Part | Answer |
|---|---|
| a) in 8-bit binary | ___ |
| a) in 8-bit binary | ___ |
| a) in 8-bit binary | ___ |
| b) Minimum bits for 1000 | ___ |
| c) Largest number with 3 hex digits | ___ |
The idea
Three numbers, three bases, three different methods, and it pays to choose the shortest for each one: divisions (or sum of weights) for the decimal, groups of 4 bits for the hexadecimal and groups of 3 for the octal. Then two range questions solved with powers, no conversions. And one rule of the format: 8 bits means writing exactly 8, with zeros on the left if needed.
Step by step
a1) . By sum of weights: 97 − 64 = 33; 33 − 32 = 1; 1 − 1 = 0. Weights used: 64, 32 and 1, positions 6, 5 and 0. With 8 bits: 01100001. (If you prefer divisions: remainders 1, 0, 0, 0, 0, 1 and quotient 1 → 1100001, completed with a 0 in front.)
The sum of weights of a1), row by row. Go through the weights of 8 bits from largest to smallest and, for each one, ask whether it fits in what is left:
| Weight | Does it fit in what is left? | Bit | Left | Why |
|---|---|---|---|---|
| 128 | No (97) | 0 | 97 | 128 is more than 97 |
| 64 | Yes | 1 | 33 | 97 − 64 = 33 |
| 32 | Yes | 1 | 1 | 33 − 32 = 1 |
| 16 | No | 0 | 1 | Only 1 is left |
| 8 | No | 0 | 1 | 8 is more than 1 |
| 4 | No | 0 | 1 | 4 is more than 1 |
| 2 | No | 0 | 1 | 2 is more than 1 |
| 1 | Yes | 1 | 0 | 0 is left: done |
Read from top to bottom: 01100001. Starting with 128 pays off: the 0 on the left is already written.
a2) . Each digit by its 4 bits: B = 1011, 6 = 0110. Result: 10110110. Not a single division.
a3) . Each digit by its 3 bits: 1 = 001, 4 = 100, 7 = 111 → 001100111, which is 9 bits. The first one is a padding 0: with 8 bits, 01100111. If the first bit had been a 1, the number would not fit in 8 bits.
What would happen if the octal number were 547 instead of 147?
Each digit by its 3 bits: 5 = 101, 4 = 100, 7 = 111, so you get 101100111. That is 9 bits and the first one is a 1, not a padding 0: you cannot drop it without changing the number.
Check with the sum of weights: 5 · 64 + 4 · 8 + 7 = 359. With 8 bits the largest number is 255, so 547 in octal does not fit in 8 bits. In the exam that is the answer, with the calculation, without cutting off the bit on the left.
b) With m bits the largest number is . and : 10 bits.
c) With m digits in base 16 the largest number is : 4095 (FFF).
Why is the largest one the power minus 1? With 8 bits, the largest number has all its bits set to 1: 11111111 = 255. Add 1 and it becomes 100000000, which already needs 9 bits and is worth 256. That is why the largest with 8 bits is 256 − 1. Hexadecimal works the same way: FFF + 1 = 1000 in hexadecimal, which is 4096, and the largest with 3 digits is 4096 − 1 = 4095. To check b): 1000 in binary is 1111101000, which has 10 digits.
| Part | Answer |
|---|---|
| a) | 01100001 |
| a) | 10110110 |
| a) | 01100111 |
| b) | 10 bits |
| c) | 4095 |
Check and how it is marked
Each binary number is checked with the sum of weights, in seconds: 01100001 = 64 + 32 + 1 = 97; 10110110 = 128 + 32 + 16 + 4 + 2 = 182 = ; 01100111 = 64 + 32 + 4 + 2 + 1 = 103 = .
As for the mark: in a), each number is usually worth the same (0.6 / 3 = 0.2), and in the real exam, if you translate wrongly, the error drags into all the operations that come after. That is why spending 20 seconds checking each one pays off. And make the working visible: the divisions or the groups of bits written on the separate sheet. An answer without working is not marked.
Leaving as 1100001 (7 bits) when they ask for 8. In the next topics that extra bit on the left will have a meaning (the sign), so get used now to always writing the number of bits they ask for.
Try it yourself
- Translate , and into 8-bit binary. Does any of them not fit?
- What is the minimum number of octal digits needed for the number 1000? And of hexadecimal digits?
Common mistakes in this practice
- Reading the remainders in the order they come out. The first remainder is the least significant bit: bottom to top, starting with the last quotient.
- Dividing the fractional part. What comes after the point is multiplied by 2, and its digits are read from top to bottom.
- Grouping from the left or padding on the inside. Outwards from the point; the zeros, on the outside.
- Forgetting the number of bits asked for. «8 bits» means 8 digits, with zeros on the left.
- Confusing «how many» with «the largest». With m digits there are numbers, but the largest is .
- Not checking. Converting the result to decimal with the sum of weights catches almost all the mistakes above.
Check it with Python
This program repeats the sums of the four problems so you can see they add up. The to_decimal function is the sum of weights as it is, with Fraction so that the fractional part is not rounded, and the multiplications of problem 2 are done by hand in a loop.
# The sums of the four practice problems, done with Python to check them.
from fractions import Fraction as F
def to_decimal(txt, base): # sum of weights: digit x base^position
whole, _, fr = txt.partition(".")
v = sum(int(c, 16) * base ** i for i, c in enumerate(reversed(whole)))
v += sum(F(int(c, 16), base ** (i + 1)) for i, c in enumerate(fr))
return v
print("P1:", [str(float(to_decimal(*x))) for x in (("10110.101", 2), ("257.6", 8), ("3B.4", 16))])
whole, fr, bits = 45, F(3, 10), ""
for _ in range(6): # 6 fractional digits, as the problem asks
fr *= 2; bits += str(int(fr)); fr -= int(fr)
rep = 45 + sum(F(int(b), 2 ** (i + 1)) for i, b in enumerate(bits))
print("P2:", f"{whole:b}.{bits}", "=", float(rep), "error", float(F(453, 10) - rep))
print("P3:", f"{0x1E6F9C:024b}", oct(0x1E6F9C), "|", f"{0o7531:b}", hex(0o7531))
print("P3 with a point:", [str(float(to_decimal(*x))) for x in (("1011.01", 2), ("13.2", 8), ("B.4", 16))])
print("P4:", [f"{x:08b}" for x in (97, 0xB6, 0o147)], "| bits for 1000:", (1000).bit_length(),
"| largest with 3 hex digits:", 16 ** 3 - 1, hex(16 ** 3 - 1))
Output (run once):
P1: ['22.625', '175.75', '59.25'] P2: 101101.010011 = 45.296875 error 0.003125 P3: 000111100110111110011100 0o7467634 | 111101011001 0xf59 P3 with a point: ['11.25', '11.25', '11.25'] P4: ['01100001', '10110110', '01100111'] | bits for 1000: 10 | largest with 3 hex digits: 4095 0xfff
Things to notice:
- In P1,
to_decimalgives 22.625, 175.75 and 59.25: the same function works for the three bases becauseint(c, 16)understands both the digits 0-9 and the letters A-F. - In P2, the 6-round loop gives 010011 and the stored value, 45.296875: the error 0.003125 comes out exact because it works with fractions.
- In P3, Python writes the octal as 0o7467634, without the 0 on the left, and the hex of 7531 as 0xf59 (lower case, which makes no difference in hex).
- In P4,
bit_length()says how many bits a number needs: 10 for 1000, as you get with the powers.
Summary
- To convert to decimal, sum of weights in any base: each digit times its power, with negative powers after the point.
- To convert from decimal, successive divisions (integer part, remainders from bottom to top) and successive multiplications (fractional part, digits from top to bottom).
- If the fractional part is not a sum of halves, quarters, eighths…, the result is periodic: cut it at the digits asked for and give the error.
- Between binary, octal and hexadecimal, groups of 3 or 4 bits from the point, with the zeros on the outside; between octal and hex, via binary.
- Range questions are solved with powers: numbers, the largest .
- Always check by another route: it is what separates a 0.1 from a 0.2 in every box.
Checklist: have you practised it?
- Have you done the four problems on paper before reading the step by step?
- Do you know why the remainders are read from bottom to top and the digits of the multiplications from top to bottom?
- Can you compute the representation error of a number with a point and say whether it is reasonable?
- Do you know where the padding zeros go on each side of the point?
- Have you checked the four problems with the Python program?
- Have you tried the «Try it yourself» tasks without looking at the theory?
If you answered yes to almost everything, you are ready for the number systems exercises, where I no longer give you the solution worked out. See you there!
Next step: exercisesNumber 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)Did this article help you? Here is how you can support SergioLearns →



