Uploaded by Sawsan Jamil

BitsAndBytesBinaryHexFloatExSolutions

advertisement
BITS and BYTES- Exercises solutions
1.
a) 4 numbers can be represented with 2 bits, 8 with 3 bits, 16 with 4 bits.
b) With each additional bit, the number of numbers that can be represented is multiplied by 2, so 5
bits can represent 32 numbers. We notice the pattern :
2 bits  4 = 22 numbers
3 bits  8 = 23 numbers
4 bits  16 = 24 numbers
5 bits  32 = 25 numbers
8 bits  28 = 256 numbers
n bits  2n numbers
8 bits can represent 256 numbers and n bits can represent 2n numbers.
2. The binary representations of odd numbers end with a 1 and that of even numbers end with a 0.
3. In the right-most column (unit column) the 0 and 1 alternate (0, 1, 0, 1, 0, 1…). In the next column
(2’s column) two 0’s are followed by two 1’s, followed by two 1’s, etc. (0, 0, 1, 1, 0, 0, 1, 1, 0, 0, …). In
the four’s column the 0 and 1 alternate by block of 4 (0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 ,1, 1, 1, 1…).
Finally in the eights’ columns the 0 and 1 alternate in block of eight (8 0’s followed by 8 one, etc…)
4. The pattern above will continue.
Binary Number
00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
Decimal Value
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Binary Number
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111
Decimal Value
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
5. Magic cards from 0 to 31.
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
16
20
24
28
17
21
25
29
18
22
26
30
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
19
23
27
31
6. Find the decimal values of the following binary numbers. (Note: to make them more readable we
often write the digits of a binary numbers by groups of four.)
a) 1000 00002 = 128 (27 = 128 or use table below)
b) 1111 11112  The number before 1 0000 0000 which is 28 = 256. So 1111 111 is
255. Or use table below.
c) 0010 11102 = 46(from table below: 32 +8 + 4 + 2 = 46)
d) 1011 00002 = 176 (from table below: 128 + 32 + 16 = 176)
128
a)
b)
c)
d)
64
32
16
8
4
2
1
1
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
1
0
1
1
0
1
0
1
1
0
0
0
1
0
7.
a)
b)
c)
d)
64 = 26 so 64 = 100 00002
65 = 64 + 1 so 65 = 100 00012
43 43 – 32 = 11 11 – 8 = 3 3 – 2 = 1 1- 1 = 0
43 = 10 10112
213
213 – 128 = 85 85 – 64 = 21 21 – 16 = 5 5 – 4 = 1 1 – 1 = 0 so 213 = 1101 01012
128
64
65
43
213
64
32
16
8
1
1
1
2
1
1
1
1
1
1
4
1
1
1
1
1
8. 28 = 256 nonnegative integers can be represented with a byte. The largest integer that can be
written with one byte is 1111 11112 = 255.
9. Convert the following hexadecimal numbers to decimals.
a) 3A16 = 3⋅16 + 10 = 58
b) 61216 = 6⋅162 + 1⋅16 + 2 = 1554
c) FEB216 = 15⋅163 + 14⋅162 + 11⋅16 + 2 = 65,202
10. Convert the following binary numbers to hexadecimals.
a) 101100101= 0001 0110 0101 = 16516
b) 10001001111 = 0100 0100 1111 = 44F16
11. Convert the hexadecimal numbers from question 9 . to binary.
a) 3A16 = 0011 10102
b) 61216 = 0110 0001 00102
c) FEB216 = 1111 1110 1011 00102
Exercises
12. Write the following numbers in scientific notation.
a. 231 = 2.31 ⋅ 102
b. 34.212 = 3.4212 ⋅ 10
c. – 3409992 = -3.409992 ⋅ 106
d. 0.01023 = 1.023 ⋅ 10-2
13. Write the following numbers in their decimal form.
a. – 9.86 ⋅ 102 = -986
b. 1.24 ⋅ 103 =1,240
c. 6.9087 ⋅ 10-5 = 0.000069087
d. – 8.349E+2 = -834.9
14. Give the 10-digit floating- point representations with a 6-digit mantissa and 3-digit exponent of the
following numbers:
a. 3892  +389200-02
b. .93452  +934520-06
c. 4,231,123  +423112+01
d. -0.0023012  -230120-08
15. In this problem we consider the same10-digit floating- point representation as in question 16.
Consider the number 0.234211.
a. What is its floating-point representation?
+234211-06
b. What is the smallest number larger than 0.234211 that has a floating-point representation
different from 0.234211 without loss of precision?
(Hint: increase the mantissa you found in a) by 1 and convert the number back to decimal.)
Add one to mantissa: +234212-06  0.234212
c. Give a number that would have same floating-point representation as 0.234211 and a
number that would have same floating-point representation as the number you found in
b). Choose the 2 numbers so that they are between 0.234211 and the number found in b).
0.2342113 has the same representation as 0.234211 (replace the last 3 by any digit
between 1 and 4 and it would work).
0.2342116 has the same representation as 0.234212 (replace the 6 by any digit between 5
and 9 and it would work).
The two given numbers are between 0.234211 and 0.234212.
Download