0% found this document useful (0 votes)
45 views5 pages

02 - Data Representation - Exercise Sheet 2 (Solutions) - 1271758327

Data Representation exercises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views5 pages

02 - Data Representation - Exercise Sheet 2 (Solutions) - 1271758327

Data Representation exercises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Computer Systems [2024-25]

Topic 1: Data Representation – Exercise Sheet #2 [Solutions]


Q#1: Convert the following negative decimal integers into sign-and-magnitude and two’s complement
representations (using 16 bits):

Decimal Number Sign-and-Magnitude Two’s Complement


Representation Representation

-153 1000 0000 1001 1001 1111 1111 0110 0111

-421 1000 0001 1010 0101 1111 1110 0101 1011

-3276 1000 1100 1100 1100 1111 0011 0011 0100


1000 1101 1101 1101 0111 0010 0010 0011
-36317 (Out of range, represents -3549) (Out of range, represents 29219)

Q#2: Convert the following binary numbers (using 16 bits) into decimal equivalent using sign-and-
magnitude and two’s complement interpretations:

Binary Representation Decimal using Sign-and- Decimal using


Magnitude Two’s Complement

0000 0000 1011 1101 189 189

1000 1100 1011 1001 -3257 -29511

1000 1111 0000 1010 -3850 -28918

1111 1111 1111 1111 -32767 -1

Q#3: Calculate the range of numbers that could be represented using different representations:

No of Unsigned Numbers Sign-and-Magnitude Two’s Complement


Bits (Min to Max) (Min to Max) (Min to Max)
8 0 to 255 −127 to +127 −128 to +127
16 0 to 65535 −32767 to +32767 −32768 to +32767
32 0 to 4294967295 −2147483647 to +2147483647 −2147483648 to +2147483647
64 0 to 1.844674407×10¹⁹ −9.223372037×10¹⁸ to −9.223372037×10¹⁸ to
+9.223372037×10¹⁸ +9.223372037×10¹⁸
128 0 to 3.402823669×10³⁸ −1.701411835×10³⁸ to −1.701411835×10³⁸ to
+1.701411835×10³⁸ +1.701411835×10³⁸
Q#4: What would be the result of adding a number to its one’s complement? What would be the result
of adding an integer to its two’s complement?

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

The normalized representations are given below:


a) 1.1000111 x 23 b) 1.01110011 x 2-1 c) 1.0101 x 2-6 d) 1.10100101 x 210

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.

Decimal Number Fixed Point Sign-and-Magnitude Fixed Point Two’s Complement


Representation (10.6 format) Representation (10.6 format)

11.40625 0000001011.011010 0000001011.011010

141.8125 0010001101.110100 0010001101.110100

-412.21875 1110011100.001110 1001100011.110010

-465.09375 1111010001.000110 1000101110.111010

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?

Decimal Number Fixed Point Sign-and-Magnitude Decimal Number Same as Original?


(Original) Representation (3.5 format) (After Conversion)

3.635 011.10100 3.625 No

-2.10 110.00011 -2.09375 No

-3.33 111.01010 -3.3125 No

3.14159 011.00100 3.125 No

Q#8: Convert the following numbers into IEEE 754 (32-bit) floating point format with 8-bit exponent:

Decimal Number IEEE 754 Floating Point Representation (32-bit)

Conversion to binary gives: 1101000.0011


104.1875 Normalized representation: 1.1010000011 x 26
Biased Exponent: 6 + 127 = 133 = (1000 0101)2
Mantissa to be stored: (.101 0000 0110 0000 0000 0000)2
Final Representation:
0 1000 0101 101 0000 0110 0000 0000 0000
Conversion to binary gives: 1100.101001
-12.640625 Normalized representation: 1.100101001 x 23
Biased Exponent: 3 + 127 = 130 = (1000 0010)2
Mantissa to be stored: (.100 1010 0100 0000 0000 0000)2
Final Representation:
1 1000 0010 100 1010 0100 0000 0000 0000
Conversion to binary gives: 10001100101.000110011
1125.10 Normalized representation: 1.0001100101000110011 x 210
Biased Exponent: 10 + 127 = 137 = (1000 1001)2
Mantissa to be stored: (.000 1100 1010 0011 0011 0011)2
Final Representation:
0 1000 1001 000 1100 1010 0011 0011 0011
Conversion to binary gives: 0.00000000110110000100010011010000...
-0.0033 Normalized representation: 1.10110000100010011010000... x 2-9
Biased Exponent: -9 + 127 = 118 = (0111 0110)2
Mantissa to be stored: (.101 1000 0100 0100 1101 0000)2
Final Representation:
1 0111 0110 101 1000 0100 0100 1101 0000
Q#9: Given the following numbers in IEEE 754 (32-bit) floating point format with 8-bit exponent,
calculate the decimal real numbers.

IEEE 754 Floating Point Decimal Number


Representation (32-bit)

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

Binary number: 0.0000001011


Decimal value: 0.010742188

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.

You might also like