Number and data questions

Conversions, units and file sizes at speed, with the checks that catch mistakes.

F13.5Exam preparationGCSE15 min

Covers OCR J277 1.2.4 Data storage · AQA 8525 3.3.2 Converting between number bases · Edexcel 1CP2 2.1.3 Denary and 8-bit binary

Do this lesson in the simulator

Binary, hexadecimal, units and character codes come up on every paper, and they are the easiest marks on it: there is one right answer and you can check it yourself. This lesson is the method for each, the checks that catch a slip, and a drill to make them automatic.

Show your working

Most conversion questions carry a mark for the method, so an answer with working can still score when the number is wrong. Write the place values down every time:

128  64  32  16  8  4  2  1

The five conversions

Binary to denary. Write the place values above the bits, add up the ones under a 1. 01101001 is 64 + 32 + 8 + 1 = 105.

Denary to binary. Work left to right along the place values: take the value if it fits, write 1, and subtract; otherwise write 0. Check by adding the ones back up.

The place values 128 to 1 over the bits 01101001, with the values under a 1 added to 105, and 105 worked back to binaryplace valuebitleft over(from 105)1280105no64141- 643219- 321609no811- 8401no201no110- 1binary to denary: add the place values over each 164 + 32 + 8 + 1 = 105denary to binary: left to right, write 1 and subtract where the value fitscheck: the left over reaches 0 at the end
One grid does both jobs. Reading down, the place values over a 1 add up to 105. Reading along, 105 is taken apart from the left: 128 does not fit, 64 does and leaves 41, and so on until nothing is left.

Binary to hex. Split into nibbles of four bits from the right, and convert each. 10110110 is 1011 0110 = B6.

Hex to binary. Each digit becomes four bits, leading zeros included. C4 is 1100 0100.

Hex to denary. First digit times 16, plus the second. 3F is 3 × 16 + 15 = 63.

10110110 split into two nibbles, 1011 and 0110, which are B and 6; and 3F worked out as 3 times 16 plus 15binary to hex: 10110110814021118 + 2 + 1 = 11B804121104 + 2 = 664 bits a digit, from the right: 10110110 is B6hex to denary: 3F16s33 × 16481sF15 × 115+48 + 15 = 63F is 15, not 16
Hex is binary in groups of four. Each nibble is worked out with 8, 4, 2 and 1, so no nibble can be more than 15, which is F. Going to denary, the first digit counts 16s and the second counts 1s.

The checks that catch slips

  • An 8-bit binary answer has exactly 8 digits. Count them.
  • Binary ending in 0 is even; ending in 1 is odd. Does that match your denary?
  • Hex F is 15, not 16.
  • The largest 8-bit number is 255, and there are 256 different values: one more than the largest.
  • A left shift multiplies, a right shift divides, and a right shift can lose a remainder.

Units and file sizes

bits → bytes → kB → MB → GB, a thousand at a time (or 1024 for the binary prefixes: the question will tell you). Eight bits in a byte.

Bits, bytes, kB, MB and GB in a row: divide by 8 then by 1000 going up, multiply going downbits÷ 8× 8bytes÷ 1000× 1000kB÷ 1000× 1000MB÷ 1000× 1000GBto a bigger unit: divideto a smaller unit: multiply1024 in place of each 1000 for the binary prefixes, when the question says so
One step at a time: 8 bits make a byte, then a thousand of each make the next. Going to a bigger unit the number gets smaller, so you divide; if your answer grew, you went the wrong way.
  • Image: width × height × colour depth, in bits.
  • Sound: sample rate × duration × bit depth (× channels), in bits.
  • Text: characters × bits per character.

Convert to the unit the question asks for, and write the unit down: a number with no unit often loses the mark.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# a 64 by 48 image at 8 bits a pixel
bits = 64 * 48 * 8
print(bits, "bits =", bits / 8, "bytes =", bits / 8 / 1000, "kB")

# 5 seconds of sound, 8 kHz, 8-bit, one channel
bits = 8000 * 5 * 8
print(bits, "bits =", bits / 8 / 1000, "kB")

Run this in the simulator

Character codes

ASCII is 7 bits, so 128 characters. The exam facts worth holding: capital A is 65, lower-case a is 97, and 0 is 48. The gap between a capital and its lower case is 32, and letters run in order, so C is A + 2.

Task: the conversion drill

For each number in numbers, print <denary> = <8-bit binary> = <2-digit hex>, working each one out yourself rather than using bin(), hex() or format(). Then for the image in image (width, height, bits per pixel), print image: <n> bits and image: <n> kB, and for sound (rate, seconds, bit depth) print sound: <n> bits and sound: <n> kB. Give the kB to 1 decimal place.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

numbers = [5, 77, 200, 255]
image = (64, 48, 8)        # width, height, bits per pixel
sound = (8000, 5, 8)       # samples a second, seconds, bits a sample

Challenges

  1. Add a column for the number after a left shift of one place. What happens to 200?
  2. Work out the size of a 10-second stereo recording at 44,100 Hz and 16 bits.
  3. Time yourself converting ten random numbers. Where do you slow down?