02 - Data Representation - Exercise Sheet 2 (Solutions) - 1271758327
02 - Data Representation - Exercise Sheet 2 (Solutions) - 1271758327
Q#2: Convert the following binary numbers (using 16 bits) into decimal equivalent using sign-and-
magnitude and two’s complement interpretations:
Q#3: Calculate the range of numbers that could be represented using different representations:
When you add a number to its one's complement, the result is always a bit pattern where all the bits are
set to 1. The value of this number will depend on how we interpret it. For example, when using sign-
and-magnitude representation (11111111)2 will be equal to (-127)10 and in two’s complement
representation it will be equal to (-1) 10. In general, for an n-bit number, the result of adding a number to
its one's complement will be 2n−1.
When you add an integer to its two’s complement, the result is always zero. When you add the number
x and its two's complement, the binary result overflows, leaving a sum of zero. This is because the
two's complement is effectively the negative representation of the original number in the binary system.
Q#5: Normalize the following binary floating-point numbers. Explicitly show the value of the
exponent after normalization.
a) 1100.0111 b) 10111.0011 x 2-5 c) 0.0000010101 d) 1101.00101 x 27
Q#6: Convert the following decimal real numbers into fixed point representation, both in sign-and-
magnitude and two’s complement representations (using 16 bits). For fixed point sign-and-magnitude,
use 10 bits (including sign bit) for the integer part and 6 bits for the fractional part.
Note: For 2’s complement representation of a negative real number, we initially assume the number to
be positive, convert to binary in the same way as fixed point conversion and apply two’s complement
on the binary representation to get the final answer.
Q#7: Convert the following decimal real numbers into fixed point representation (using 8 bits).
Convert the fixed point back to decimal real numbers. Do you get the same value as the original?
Q#8: Convert the following numbers into IEEE 754 (32-bit) floating point format with 8-bit exponent:
0 1000 0111 101 1100 1100 0000 0000 0000 Sign bit: 0 (+ve)
Biased Exponent: (1000 0111)2 = 135
Real Exponent: 135 – 127 = 8
Stored Mantissa: (.101 1100 1100 0000 0000 0000)2
Actual Mantissa: (1.101 1100 1100 0000 0000 0000)2
Normalized representation: 1.101110011 x 28
Binary number: 110111001.1
Decimal value: 441.5
0 0111 1000 011 0000 0000 0000 0000 0000 Sign bit: 0 (+ve)
Biased Exponent: (0111 1000)2 = 120
Real Exponent: 120 – 127 = -7
Stored Mantissa: (011 0000 0000 0000 0000 0000)2
Actual Mantissa: (1.011 0000 0000 0000 0000 0000)2
Normalized representation: 1.011 x 2-7
1 1000 1010 101 0101 0000 0100 0000 0000 Sign bit: 1 (-ve)
Biased Exponent: (1000 1010)2 = 138
Real Exponent: 138 – 127 = 11
Stored Mantissa: (101 0101 0000 0100 0000 0000)2
Actual Mantissa: (1.101 0101 0000 0100 0000 0000)2
Normalized representation: 1.1010101000001 x 211
Binary number: 110101010000.01
Decimal value: -3408.25
1 0111 1010 100 0000 0000 0000 0000 0000 Sign bit: 1 (-ve)
Biased Exponent: (0111 1010)2 = 122
Real Exponent: 122 – 127 = -5
Stored Mantissa: (100 0000 0000 0000 0000 0000)2
Actual Mantissa: (1.100 0000 0000 0000 0000 0000)2
Normalized representation: 1.1 x 2-5
Binary number: 0.000011
Decimal value: -0.046875
Q#10: The data-type Float (32-bit total = 23-bit mantissa, 8-bit exponent) gives us about 7-8 significant
decimal digits. The data-type Double (64-bit total = 52-bit mantissa, 11-bit exponent) gives us about
15-16 significant decimal digits.
Let’s create a new data-type called Triple, which has 96-bits total; a 78-bit mantissa and a 17-bit
exponent. Roughly how many significant decimal digits will this type give us?
The mantissa has 78-bits, so (when we include the hidden bit) we get 79 significant bits; or 2^79
values. 2^79 = 6.044629098 x 10^23
(we can work this out through various methods, e.g. using logarithms of base 10). Therefore we have
roughly 23-24 significant decimal digits.
Sources:
Forouzan (2023) Foundations of Computer Science. Cengage Learning.