A1Arena Open the app

Number Bases and Data Representation

Computer Studies · WAEC and JAMB · SS2 and SS3

This is the one chapter in Computer Studies that is marked like mathematics: the method earns part of the mark and the final figure earns the rest. Every conversion can be checked by converting back, so there is no excuse for a wrong answer here.

What you need to know

  • A number base is the number of distinct digits a counting system uses. Binary is base 2 and uses 0 and 1. Octal is base 8 and uses 0 to 7. Decimal is base 10 and uses 0 to 9. Hexadecimal is base 16 and uses 0 to 9 followed by A, B, C, D, E and F for ten to fifteen.
  • Computers work in binary because an electronic circuit has only two reliable states, on and off, which map onto 1 and 0. Octal and hexadecimal exist as human shorthand for long binary strings, not as something the machine itself uses.
  • To convert any base to decimal, write the place values and expand. In base b the place values from the right are b^0, b^1, b^2 and so on. For example 1101(2) = 1x8 + 1x4 + 0x2 + 1x1 = 13(10), and 2AF(16) = 2x256 + 10x16 + 15x1 = 687(10).
  • To convert decimal to any base, divide repeatedly by the base and read the remainders from the bottom upwards. For 25 to binary: 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, so 25(10) = 11001(2). Check: 16 + 8 + 1 = 25.
  • To convert binary to octal, group the bits into threes from the right, padding the left group with zeros if needed, and write the octal digit for each group. 110101(2) becomes 110 101, which is 6 and 5, so the answer is 65(8). Confirm: 6x8 + 5 = 53, and 110101(2) = 32 + 16 + 4 + 1 = 53.
  • To convert binary to hexadecimal, group the bits into fours from the right instead. 110101(2) becomes 0011 0101, which is 3 and 5, so the answer is 35(16). Confirm: 3x16 + 5 = 53, the same value.
  • Going the other way, replace each octal digit with three bits and each hexadecimal digit with four bits. 357(8) becomes 011 101 111 = 11101111(2), and 2AF(16) becomes 0010 1010 1111 = 1010101111(2) once the leading zeros are dropped.
  • For a fraction, multiply the fractional part by the base repeatedly and read the whole-number parts downwards. 0.625 x 2 = 1.25 so write 1; 0.25 x 2 = 0.5 so write 0; 0.5 x 2 = 1.0 so write 1 and stop. Therefore 0.625(10) = 0.101(2). Going back the other way, a mixed binary number is expanded with negative powers after the point: 1101.101(2) = 8 + 4 + 0 + 1 + 0.5 + 0 + 0.125 = 13.625(10).
  • Binary addition follows four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 0 carry 1. So 1011 + 1101 = 11000, which checks out as 11 + 13 = 24. Binary multiplication is simpler still, since multiplying by 1 copies the number and multiplying by 0 gives zeros: 101 x 11 = 1111, that is 5 x 3 = 15.
  • Negative numbers are stored in two's complement form. To obtain the two's complement, invert every bit to get the one's complement and then add 1. For minus five in eight bits: 5 is 00000101, inverting gives 11111010, adding 1 gives 11111011.
  • Units of storage build on the bit. A bit is a single binary digit, a nibble is 4 bits, a byte is 8 bits and holds one character, and a word is the number of bits the processor handles at once. Above that, 1 KB = 1024 bytes, 1 MB = 1024 KB, 1 GB = 1024 MB and 1 TB = 1024 GB. The multiplier is 1024 and not 1000, because 1024 is 2 raised to the power 10.
  • With n bits you can represent 2^n different values, running from 0 to 2^n minus 1. Eight bits therefore give 256 different patterns, from 0 to 255, which is why a single byte can hold any one of 256 characters.
  • Character coding schemes turn letters into numbers. ASCII, the American Standard Code for Information Interchange, is a 7-bit code giving 128 characters, in which capital A is 65, small a is 97 and the digit zero is 48; extended ASCII uses 8 bits for 256 characters. BCD codes each decimal digit separately in four bits. EBCDIC is IBM's 8-bit mainframe code. Unicode uses more bits so that it can represent the characters of virtually every written language, which is why Yoruba, Hausa and Igbo diacritics display correctly on modern systems.
  • A parity bit is an extra bit added to a group of bits so that the total number of ones is always even under even parity or always odd under odd parity. If the count arrives wrong, the receiver knows a bit was corrupted in transmission.

Key terms

Number base
The number of distinct digits, including zero, that a counting system uses to represent values.
Bit
A binary digit, the smallest unit of data in a computer, having the value 0 or 1.
Byte
A group of eight bits, the amount of storage normally used to hold one character.
Place value
The value a digit carries because of its position, equal to the base raised to the power of that position counted from zero at the right.
ASCII
The American Standard Code for Information Interchange, a 7-bit coding scheme that assigns a number to each of 128 characters.
Two's complement
The representation of a negative binary number obtained by inverting every bit of the positive value and adding one.
Parity bit
An extra bit added to a group of bits to make the total number of ones even or odd, used to detect errors in transmission.

Formulae

  • Any base to decimal: value = d(n) x b^n + ... + d(1) x b^1 + d(0) x b^0
  • Decimal to any base: divide repeatedly by the base and read the remainders from the bottom upwards
  • Decimal fraction to any base: multiply the fraction repeatedly by the base and read the whole-number parts from the top downwards
  • Binary to octal: group the bits in threes from the right. Binary to hexadecimal: group the bits in fours from the right
  • Octal to binary: write each digit as 3 bits. Hexadecimal to binary: write each digit as 4 bits
  • Two's complement = one's complement (invert every bit) + 1
  • With n bits: number of values = 2^n, largest unsigned value = 2^n - 1
  • 1 nibble = 4 bits; 1 byte = 8 bits; 1 KB = 1024 bytes; 1 MB = 1024 KB; 1 GB = 1024 MB; 1 TB = 1024 GB
  • Hexadecimal letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15

Worked examples

Convert 156(10) to (a) binary (b) octal (c) hexadecimal. (9 marks)

  1. (a) Divide by 2 repeatedly: 156/2 = 78 r 0, 78/2 = 39 r 0, 39/2 = 19 r 1, 19/2 = 9 r 1, 9/2 = 4 r 1, 4/2 = 2 r 0, 2/2 = 1 r 0, 1/2 = 0 r 1.
  2. Read the remainders upwards from the last to the first: 10011100.
  3. (b) Divide by 8 repeatedly: 156/8 = 19 r 4, 19/8 = 2 r 3, 2/8 = 0 r 2. Reading upwards gives 234.
  4. (c) Divide by 16 repeatedly: 156/16 = 9 r 12, and 12 is written as C; 9/16 = 0 r 9. Reading upwards gives 9C.
  5. Check all three by expanding: 10011100 = 128 + 16 + 8 + 4 = 156; 234(8) = 2x64 + 3x8 + 4 = 128 + 24 + 4 = 156; 9C(16) = 9x16 + 12 = 144 + 12 = 156.

Convert 2AF(16) to decimal and to binary, and convert 357(8) to binary. (8 marks)

  1. In hexadecimal A stands for 10 and F stands for 15, so expand 2AF with place values 16^2, 16^1 and 16^0: 2x256 + 10x16 + 15x1.
  2. 512 + 160 + 15 = 687, so 2AF(16) = 687(10).
  3. For the binary, replace each hexadecimal digit with four bits: 2 = 0010, A = 1010, F = 1111, giving 001010101111, which is 1010101111 after dropping the two leading zeros.
  4. For 357(8), replace each octal digit with three bits: 3 = 011, 5 = 101, 7 = 111, giving 011101111, which is 11101111 after dropping the leading zero.
  5. Check: 1010101111 = 512 + 128 + 32 + 8 + 4 + 2 + 1 = 687, and 11101111 = 128 + 64 + 32 + 8 + 4 + 2 + 1 = 239, while 357(8) = 3x64 + 5x8 + 7 = 192 + 40 + 7 = 239.

The mistake to avoid

Candidates read the remainders downwards instead of upwards and hand in the binary number reversed, which turns 25 into 10011 instead of 11001. Write the remainders in a column and draw an arrow pointing up before you copy the answer. The second standing error is using 1000 instead of 1024 when converting storage units, and the third is forgetting that A to F stand for ten to fifteen, so that 9C is read as ninety-something rather than 156.

In the exam

Always check your answer by converting back, because this is the only topic on the paper where a check takes ten seconds and guarantees the mark. Show the division column and the remainders in full, since method marks are awarded even when the final figure slips. Write the base as a subscript or in brackets on every line, because an unlabelled answer in a question that mixes bases can be read as decimal and marked wrong.