CSC340 - HW3
CSC340 - HW3
CSC340 - HW3
Assignment 3
First Name
Last Name
ID#
Email Address
Smallest Positive:
If the storage is returned to normal, the minimum
positive floating point # is…
0.12 x 2 = 0.000012 = 1/32 = 0.03125
−4
Explanation:
In this case, bias is selected such that the largest exponent
value that can be represented using a given number of bits
is non-negative.
In this case, with a 3-bit exponent, the largest unsigned
integer value that can be represented is 7. That means an
exponent of 7 – 3 = 4. That also means that the largest
exponent value that can be represented with a 3-bit
exponent and a bias of 3 is 4, which is non-negative.
Question 2: (3 pts)
Assume we are using the simple model for floating-point representation as given in this
book (the representation uses a 14-bit format, 5 bits for the exponent with a bias of 15, a
normalized mantissa of 8 bits, and a single sign bit for the number):
a) Show how the computer would represent the numbers 100.0 and 0.25 using this
floating-point format.
b) Show how the computer would add the two floating-point numbers in part a by
changing one of the numbers so they are both expressed using the same power of 2.
c) Show how the computer would represent the sum in part b using the given floating point
representation. What decimal value for the sum is the computer actually storing?
Explain.
Answer:
Sign bit = 0
Exponent (5 bits) = 10110.
Significant bits of 8 = 11001000.
0 1 0 1 1 0 1 1 0 0 1 0 0 0
01011011001000
Sign bit = 0
Exponent (5 bits) = 01110.
Significant bits of 8 = 10000000.
0 0 1 1 1 0 1 0 0 0 0 0 0 0
00111010000000
b) 100.0 = .11001000 * 27
0.25 = .1* 2-1
0.25 ~ 0.000000001 * 27
0 1 0 1 1 0 1 1 0 0 1 0 0 0
.1100100 * 27 = 1100100
Question 3: (2 pts)
What causes divide underflow and what can be done about it?
Answer:
In arithmetic terms, “divide overflow” is caused by a
situation where the divisor is much smaller than the
dividend. That results in division that equates to a
“division by zero” error. To avoid it, you could use
repeated subtraction.
Question 4: (4 pts)
Let a = 1.0 29, b = - 1.0 29 and c = 1.0 21. Using the floating-point model described in
the text (the representation uses a 14-bit format, 5 bits for the exponent with a bias of 15, a
normalized mantissa of 8 bits, and a single sign bit for the number), perform the following
calculations, paying close attention to the order of operations. What can you say about the
algebraic properties of floating-point arithmetic in our finite model? Do you think this
algebraic anomaly holds under multiplication as well as addition?
b + (a + c) =
(b + a) + c =
Answer:
Let a = 1.0 * 29, b = - 1.0 * 29 and c = 1.0 * 21
b = - 1.0 * 29
c = 1.0 * 21
sign bit = 0
Mantissa = 0
Exponent = 1
Convert in binary
= 1 + 15 = (10000)2
Therefore, our number is : 0 10000 00000000
c = 0 10000 00000000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b + (a + c) = b + (a + c)
for (a + c) 0 11000 00000000
0 10000 00000000
Therefore, (a + c) = 0 11000 00000000
b + (a + c) 1 11000 00000000
0 11000 00000000
(b + a) + c ≠ b + (a + c)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Floating point overflow & underflow can drive a
program
crash.
Therefore, I obtain:
0 10000010 100100000000000000000000
0 10000010.100100000000000000000000
b) For “-1.5” …
1 01111111.10000000000000000000000
c) For 0.75
d) For 26.625
Question 6: (4 pts)
Show how each of the following floating point values would be stored using IEEE-754 double
precision (be sure to indicate the sign bit, the exponent, and the significand fields):
a) 12.5 b) −1.5 c) 0.75 d) 26.625
Answer:
For our IEEE 754(Single precision):
sign (1 bit) =0
exponent(8 bits) = 10000010
mantissa(23 bits) = 10010000----0
b). -1.5=
1.5 = 1.1 = 1.1 x 20
Sign =1
exponent = 01111111
mantissa = 10000-----0
c). 0.75=
Sign =0
exponent = 01111110
mantissa = 10000-----0
d) 26.625
Sign =0
exponent = 10000011
mantissa = 1010000-----0
Question 7: (4 pts)
a) The ASCII code for the letter A is 1000001, and the ASCII code for the letter a is 1100001.
Given that the ASCII code for the letter G is 1000111, without looking at Table 2.7, what is
the ASCII code for the letter g?
b) The EBCDIC code for the letter A is 1100 0001, and the EBCDIC code for the letter a is
1000 0001. Given that the EBCDIC code for the letter G is 1100 0111, without looking at
Table 2.6, what is the EBCDIC code for the letter g?
c) The ASCII code for the letter A is 1000001, and the ASCII code for the letter a is 1100001.
Given that the ASCII code for the letter Q is 1010001, without looking at Table 2.7, what
is the ASCII code for the letter q?
d) The EBCDIC code for the letter J is 1101 0001, and the EBCDIC code for the letter j is
1001 0001. Given that the EBCDIC code for the letter Q is 1101 1000, without looking at
Table 2.6, what is the EBCDIC code for the letter q?
e) In general, if you were going to write a program to convert uppercase ASCII characters
to lowercase, how would you do it? Looking at Table 2.6, could you use the same
algorithm to convert uppercase EBCDIC letters to lowercase?
f) If you were tasked with interfacing an ECIDIC-based computer with an ASCII or Unicode
computer, what would be the best way to convert the EBCIDIC characters to ASCII
characters?
Answer:
STEP-3: Convert the ASCII code for letter G into decimal value.
ASCII code for letter G is 1000111
1000111 = 1x26 + 0x25 + 0x24 + 0x23 + 1x22 + 1x21 +1x20
= 1x64 + 0x32 + 0x16 + 0x8 + 1x4 + 1x2 + 1x1
= 64 + 0 + 0 + 0 + 4 + 2 + 1
= 71
STEP-4: Add the decimal value of G to the difference found in step 3 for:
Decimal value of g.
Decimal value of G = 71
Difference = 32
Binary code of letter g = 71 + 32 = 103
2 103
2 51 1
2 25 1
2 13 1
2 6 0
2 3 0
1 1
STEP-3: Convert the EBCDIC code for letter G into decimal value.
EBCDIC code for letter G is 11000111
11000111= 1x27 +1x26 + 0x25 + 0x24 + 0x23 + 1x22 + 1x21 +1x20
= 1x128 +1x64 +0x32 +0x16 +0x8 +1x4 +1x2 + 1x1
= 128 + 64 + 0 + 0 + 0 + 4 + 2 + 1
= 199
2 67 1
2 33 1
2 16 1
2 8 0
2 4 0
2 2 0
1 0
STEP-3: Convert the ASCII code for letter Q into decimal value.
ASCII code for letter G is 1010001
1010001 = 1x26 + 0x25 + 1x24 + 0x23 + 0x22 + 0x21 +1x20
= 1x64 + 0x32 + 1x16 + 0x8 + 0x4 + 0x2 + 1x1
= 64 + 0 + 16 + 0 + 0 + 0 + 1
= 81
STEP-4: Add the decimal value of Q to the difference found in step 3 for:
Decimal value of q.
Decimal value of Q = 81
Difference = 32
Binary code of letter q = 81 + 32 = 113
2 56 1
2 28 0
2 14 0
2 7 0
2 3 1
1 1
2 76 0
2 38 0
2 19 0
2 9 1
2 4 1
2 2 0
1 0
f)
The best way to convert EBCDIC characters to ASCII characters is:
The message:
1001010 1001111 1001000 1001110 0100000 1000100 10011111000101
First, I use the ASCII table, I can decode the message into
text.
10 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
20 ! “ # $ % % ‘ ( ) * + , - . /
30 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
40 @ A B C D E F G H I J K L M N O
50 P Q R S T U V W X Y Z [ \ ] ^ _
60 ` A B C d e f G h I j k l m n o
70 P Q R S t u v W x Y z { | } ~ DEL
For the string, each short bit string is divided into two subparts.
The subpart is then converted in hexadecimal notation that is
expressed in characters using the ASCII table.
100 1010 = 4A
1001111 = 4F
100 1000 = 48
1001110 = 4E
010 0000 = 20
100 0100 = 44
1001111 = 4F
100 0101 = 45
4A = J
4F = 0
48 = H
4E = N
20 = (space)
44 = D
4F = 0
45 = E
Question 9: (4 pts)
Compute the Hamming distance of the following code:
0011010010111100
0000011110001111
0010010110101101
0001011010011110
Answer:
0000011110001111
0001011010011110 4
4
0010010110101101 8
4
8
0011010010111100 4
Suppose we are working with an error-correcting code that will allow all single-bit errors to be
corrected for memory words of length 12. We have already calculated that we need 5 check bits,
and the length of all code words will be 17. Code words are created according to the Hamming
Algorithm presented in the text. We now receive the following code word:
01100101001001001
Assuming even parity, is this a legal code word?
If not, according to our error-correcting code, where is the error?
Answer:
The parity check equation for each check bit is the ‘XOR’
of the bits in the corresponding positions of all code words
that have a 1 in that position.
Now, I label the bits of the “received code word” from left
to right as b1, b2, ..., b17. I can construct the parity check
matrix by listing the bit positions for each of the 5 check
bits:
1. C1: 1 3 5 7 9 11 13 15 17
2. C2: 2 3 6 7 10 11 14 15
3. C3: 4 5 6 7 12 13 14 15
4. C4: 8 9 10 11 12 13 14 15
5. C5: 16 17
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rationale:
Here, both check bits C3 and C4 have a value of 1, so there
are errors in both bit positions 12 and 13. I can correct the
error by flipping the bits in those positions to their
complement, resulting in the corrected code word:
01100101001111001
Here, I use the fact that the code can correct a single-bit error
to correct both errors simultaneously.
The end