4FTC2065:
4COM2003/8 From Silicon to C
Exercise Sheet 1: Binary Representations
Complete as many as you can before next week's class. A solution sheet will be posted on Canvas
at the weekend.
Exercise 1 : Choosing the right length of bit-string
A Encoding numbers
i) How many whole numbers are there in the range 0 .. 200 inclusive?
What are the nearest powers of two to this quantity (nearest below, nearest above)?
What is the minimum length of bit-string required to ensure that a different bit-sequence
is available to represent each number in the range 0 .. 200?
How many of the available bit-sequences will be redundant if bit-strings of this length are
used to represent the whole numbers in the range 0 .. 200?
(The redundant bit-sequences are those that aren't being used to represent numbers)
B Each item in a set of 2n different items can be labelled by different n-bit string, as long as there
is an n-bit code that defines which n-bit-sequence is to be used as a label for each of them.
i) How many different labels can be provided using an 8-bit code ?
ii) How many different labels can be provided using a 16-bit code ?
Work out the decimal numbers, rather than stating powers of two.
C Suppose you have a machine that supports 16-bit unsigned binary numbers.
i) What is the smallest number that can be represented using a natural 16-bit
unsigned binary representation?
ii) What is the largest number that can be represented using a natural 16-bit
unsigned binary representation?
Exercise 2: Binary representations of natural numbers
A We may identify the bits in an n-bit string by numbering them. Conventionally they are
numbered 0 to n-1, with the right-most bit being numbered 0
If a bit-string is used to represent an unsigned binary number, what is the place value of the bits
numbered 0, 1, 2, 3, 7, 15?
B What decimal number is represented by each of the following unsigned binary numbers?
(i) 11 (ii) 101 (iii) 111 (iv) 10100 (v) 100001
(vi) 0011 (vii) 0101 (viii) 0111 (ix) 00010100 (x) 00100001
(xi) 1011 (xii) 1101 (xiii) 1111 (xiv) 10010100 (xv) 10100001
C What is the 8-bit unsigned binary representation of each of the following decimal numbers?
(i) 1 (ii) 100 (iii) 34 (iv) 57 (v) 129 (vi) 63
Exercise 3: Binary addition
A Try adding together the following pairs of binary numbers, giving the result in binary, using as
many bits as necessary
i) 1 + 101
ii) 100 + 100
iii) 1111 + 1
iv) 1010 + 1101
B Add together the following pairs of 4-bit binary numbers, giving a 4-bit result in each case.
In each case state whether or not the result overflows the representation (i.e. the resulting
number is too big to be represented in 4 bits)
i) 1011 + 0011
ii) 0111 + 0110
iii) 1110 + 0100
iv) 0001 + 1111
C Add together the following pairs of 4-bit binary numbers and give the result as a 5-bit binary
number in each case. Why is it impossible to get overflow this time?
i) 1111 + 1111
ii) 0001 + 0001
iii) 1010 + 1010
iv) 1000 + 0111
Exercise 4:
A Encoding single characters
i) What is the minimum length of bit-string required to ensure that a different bit-sequence is
available to represent each of the 26 uppercase letters in the English alphabet?
ii) What is the minimum length of bit-string required to ensure that a different bit-sequence is
available to represent each of the uppercase and lowercase letters in the English alphabet
(52 in total)?
iii) What is the minimum length of bit-string required to ensure that a different bit-sequence is
available to represent each of the uppercase and lowercase letters in the English alphabet,
and each of the decimal digits (62 in total)?
B Add together the following pairs of 8-bit binary numbers, giving each result as an 8 bit Sum and
a 1-bit carry-out
In some cases the carry-out will be 0, and in others it will be 1. What does it mean when the
carry-out is 1?
i) 10000100 + 10000100
ii) 01111010 + 10001101
iii) 00101011 + 00010101
iv) 01010101 + 01110000
C Manipulating binary representations of whole numbers
i) How can you tell whether a binary number is even or odd, without dividing by 2 or working
out what decimal number it represents?
ii) How can you multiply a binary number by 2, by 4 or by 8, without ‘doing multiplication’,
and without working out what decimal number it represents?
iii) How can you divide a binary number by 2, by 4 or by 8, without ‘doing division’, and
without working out what decimal number it represents?