View
19
Download
0
Embed Size (px)
DESCRIPTION
a
Citation preview
Exercise 3.1 A B
a.) 3174 0522
b.) 4165 1654
3.1.1 What is the sum of A and B if they represent unsigned 12-bit octal numbers? The result should be written in octal. Show your work.a.) First is to convert the octal numbers base 8into binary numbers. A B
31740522
011001111100000101010010
So in Binary A: 011 001 111 100two and B: is 000 101 010 010twoA011001111100
+B000101010010
=011111001110
The binary sum of A and B is 011 111 001 110two, in octal it is 3716.b.) Well do the same thing as in a) A B
41651654
100001110101001110101100
So the binary representation of A: 100 001 110 101two and B: 001 110 101 100two.A100001110101
+B001110101100
=110000100001
The binary sum of A and B is 110 000 100 001two, in octal it is 6041.To check this and every problem I just used the calculator on my computer and set it to programmer.
3.1.2 What is the sum of A and B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal. Show your work.Incomputer science, thesign bitis abitin asigned number representationthat indicates thesignof a number. Onlysignednumeric data types have a sign bit, and its place is usually the leftmost, where themost significant bitin unsigned numbers resides.Floating pointnumbers inIEEE formatare always signed, with the sign bit in the leftmost position. Typically if the sign bit is 1 then the number isnegative(in the case oftwos complementintegers) or non-positive (forones complementintegers,sign-and-magnitudeintegers, and floating point numbers), while 0 indicates a non-negative number (http://en.wikipedia.org/wiki/Sign_bit).We are going to convert the octal numbers into binary as in 3.1.1a.) A B
31740522
011001111100000101010010
Since the most significant bit is 0 for both A and B, we get the same value for signed numbers. The binary representation of A: 011 001 111 100two and B: 000 101 010 010two.
A011001111100
+B000101010010
=011111001110
The binary sum of A and B is 011 111 001 110two, in octal it is 3716.b.) Well start off the same way as above by converting the octal into binary. A B
41651654
100001110101001110101100
InA the most significant bit is 1, so it is negative. Leave the most significant bit which is the 1, which leaves you with:00001110101
Now you want to take the 2s complement, simply switch every 0 to 1 and every 1 to 0, and add one to the result. You will get:A2
11110001010
Take that and add 1 to it:11110001010
+1
11110001011
B is the same as before, since the number is positive.B
1654
001110101100
The binary representation of A is 11 110 001 011two, and B is 001 110 101 100two. The sum of A and B is:A211110001011
+B001110101100
=01100110111
01 100 110 111two = 1467 octal.
3.1.4 What is A B if they represent unsigned 12-bit octal numbers? The result should be written in octal. Show your work.AB
a.)70400444
b.)43653412
a.) The first step is the same as 3.1.1 and 3.1.2, convert to binary: A B
70400444
111000100000000100100100
A B:A111000100000
-B000100100100
=110011111100
110 011 111 100two, which is 6374 octal.b.) Again convert the octal into binary: A B
43653412
100011110101011100001010
A B:A110011110101
-B011100001010
=000111101011
= 000 111 101 011_two, which is 0753 octal.
3.1.5 What is A- B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal. Show your work.a.) SinceA is negative you are going to do steps similar to problem 3.1.2, drop the most significant bit giving you 11 000 100 000two, then take the 2s complement (simply switch every 0 to 1 and every 1 to 0) and then add one to the result. The table below shows the steps: A
7040
111000100000
Drop the most significant bit
11000100000
Switch 0s and 1s
00111011111
2s complement
00111100000
B is the same as before, since the number is positive.B
0444
000100100100
Now do A B:A00111100000
-B000100100100
=00010111100
00 010 111 100two is 0274 octal.b.) SinceA is negative you are going to do steps similar to problem 3.1.2, drop the most significant bit giving you 00 011 110 101two, then take the 2s complement (simply switch every 0 to 1 and every 1 to 0) and then add one to the result. The table below shows the steps: A
4365
100011110101
Drop the most significant bit
00011110101
Switch 0s and 1s
11100001010
2s complement
11100001011
B is the same as before, since the number is positive. B
3412
011100001010
A BA11100001011
-B011100001010
=00000000001
00 000 000 001two is 0001 octal.Exercise 3.2AB
a.1446672F
b.24604935
3.2.1 What is the sum of A and B if they represent unsigned 16-bit hexadecimal numbers? The result should be written in hexadecimal. Show your work.Since the left most bit is the sign bit in the binary number, then the following rule can be used with any binary number in order to figure out either it is a positive number, or a negative number: 1)If the most left bit is 0, and then the binary number is a positive number. 2) If the most left bit is 1, then the binary number is a negative number.Hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A,B,C,D,E,F (or alternatively af) to represent values ten to fifteen. (http://en.wikipedia.org/wiki/Hexadecimal)
a.) The first step is to convert from hexadecimal to binary. A B
1446672F
00010100010001100110011100101111
A + BA0001010001000110
+B0110011100101111
=0111101101110101
Now you want to convert 0111 1011 0111 0101 back into hexadecimal.0111101101110101
7B75
A + B = 7B75b.) Again convert the hexadecimal numbers into binary. A B
24604935
00100100011000000100100100110101
A + BA0010010001100000
+B0100100100110101
=0110110110010101
Now take 0110 1101 1001 0101 and convert it back into hexadecimal.0110110110010101
6D95
A + B = 6D95
3.2.2 What is the sum of A and B if they represent signed 16-bit hexadecimal numbers stored in sign-magnitude format? The result should be written in hexadecimal. Show your workAB
a.1446672F
b.24604935
a.)The first step is to convert from hexadecimal to binary.
A B
1446672F
00010100010001100110011100101111
Both A and B have zero at the most left bit, so they are positive numbers. Since both A and B are positive numbers, then the sum of A+B in singed 12-bits will be similar in unsigned16-bits.
A in binary0001010001000110
B0110011100101111
A+B (binary)0111101101110101
A+B = 7b75
b.)The first step is to convert from hexadecimal to binary. A B
24604935
00100100011000000100100100110101
Both A and B have zero at the most left bit, so they are positive numbers. Since both A and B are positive numbers, then the sum of A+B in singed 12-bits will be similar in unsigned16-bits.
A in binary0010010001100000
B0100100100110101
A+B (binary)0110110110010101
A+B= 6d95
3.2.3 Convert A into a decimal number, assuming it is unsigned.Repeat assuming it stored in sign-magnitude format. Show your work.
A
a.1446
b.2460
Unsigned Format:a.) The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) byA 1446
0001010001000110
then converting the binary number to decimal number:(0* 2^0)+(1* 2^1)+(1* 2^2)+(0* 2^3)+(0* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+(1* 2^10)+(0* 2^11) +(1* 2^12)+(0* 2^13)+(0* 2^14)+(0* 2^15)= 2+4+64+1024++4096 =5190 (base 10).
b.)The value of A is 2460 (base 16) which can be represented in a binary form (base 2) by
A 2460
0010010001100000
(0* 2^0)+(0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+(1* 2^10)+(0* 2^11)+(0* 2^12)+(1* 2^13)+(0* 2^14)+(0* 2^15)= 32+64+1024+8192 = 9312 (base 10).
Sign-Magnitude Format:a.)The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) byA 1446
0001010001000110
then converting the binary number to decimal number by the following way:
(0* 2^0)+(1* 2^1)+(1* 2^2)+(0* 2^3)+(0* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+(1* 2^10)+(0* 2^11) +(1* 2^12)+(0* 2^13)+(0* 2^14)+(0*(- 2^15))= 2+4+64+1024++4096=5190 (base 10).
b.)The value of A is 2460 (base 16) which can be represented in a binary form (base 2) byA 2460
0010010001100000
(0* 2^0)+(0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(1* 2^6)+(0* 2^7)+(0* 2^8)+(0* 2^9)+(1* 2^10)+(0* 2^11)+(0* 2^12)+(1* 2^13)+(0* 2^14)+(0* *(-2^15))= 32+64+1024+8192 = 9312 (base 10).
3.2.4 What is A B if they represent unsigned 16-bit hexadecimal numbers? The result should be written in hexadecimal. Show your work.
AB
a.C35236AE
b.5ED407A4
a.) The first step is to convert from hexadecimal to binary. Then subtract A to BA C352B36AE
11000011010100100011011010101110
1100001101010010
0011011010101110
A-B =1000110010100100
A-B= 8CA4
b.) The first step is to convert from hexadecimal to binary. Then subtract A to BA 5ED4B07A4
01011110110101000000011110100100
0101111011010100
0000011110100100
A-B =0101011100110000
A-B=5730
3.2.5 What is A B if they represent signed 16-bit hexadecimalnumbers stored in sign-magnitude format? The result should be written in hexadecimal. Show your work.AB
a.C35236AE
b.5ED407A4
a.) The first step is to convert from hexadecimal to binaryA C352B36AE
11000011010100100011011010101110
SinceA is negative you are going to take the 2s complement (simply switch every 0 to 1 and every 1 to 0) and then add one to the result0011110010101101
+1
0011110010101110
B is the same as before, since the number is positive.
A 0011110010101110
-
B0011011010101110
A-B =0000011000000000
A-B=0600
b.) The first step is to convert from hexadecimal to binary
A 5ED4B07A4
01011110110101000000011110100100
Both A and B have zero at the most left bit, so they are positive numbers. Since both A and B are positive numbers, then the sum of A-B in singed 12-bits will be similar in unsigned16-bits.A 0101111011010100
-
B0000011110100100
A-B =0101011100110000
A-B= 5730
3.2.6 Convert A into a binary number. What makes base 16 (hexadecimal) an attractive numbering system for representing values in computers?A
a.C352
b.5ED4
a.)The value of A which isC352(base 16) that can be represented in a binary form (base 2) byA C352
1100001101010010
then converting the binary number to decimal number:(0* 2^0)+(1* 2^1)+(0* 2^2)+(0* 2^3)+(1* 2^4)+(0* 2^5)+(1* 2^6)+(0* 2^7)+(1* 2^8)+(1* 2^9)+(0* 2^10)+(0* 2^11) +(0* 2^12)+(0* 2^13)+(1* 2^14)+(1* 2^15)= 50002(base 10).
b.)The value of A is5ED4(base 16) which can be represented in a binary form (base 2) byA 5ED4
0101111011010100
(0* 2^0)+(0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(0* 2^5)+(1* 2^6)+(1* 2^7)+(0* 2^8)+(1* 2^9)+(1* 2^10)+(1* 2^11)+(1* 2^12)+(0* 2^13)+(1* 2^14)+(0* 2^15)= 4+16+64+128+512+1024+2048+4096+16384 = 24276(base 10).
Exercise 3.3Overflow occurs when a result is too large to be represented accurately given afinite word size. Underflow occurs when a number is too small to be representedcorrectlya negative result when doing unsigned arithmetic, for example. (Thecase when a positive result is generated by the addition of two negative integers isalso referred to as underflow by many, but in this textbook, that is considered anoverflow.) The following table shows pairs of decimal numbers. AB
a.216255
b.185122
3.3.1 Assume A and B are unsigned 8-bit decimal integers. CalculateA B. Is there overflow, underflow, or neither?a.) The first step is to convert from decimal to binary, then subtract
A 216B 255
110110001111111
A11011000
-B1111111
=1100111
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow by many, but in this textbook, that is considered an overflow." (given by the book) There is underflow
b.) The first step is to convert from decimal to binary, then subtractA 185B 122
101110011111010
A10111001
-B1111010
=00111111
"Underflow occurs when a number is too small to be representedcorrectlya negative result when doing unsigned arithmetic, for example. (Thecase when a positive result is generated by the addition of two negative integers isalso referred to as underflow" (given by the book)There is underflow, but in this textbook, it is considered as an overflow. Because two negative numbers give a positive number.3.3.2 Assume A and B are signed 8-bit decimal integers stored in sign magnitudeformat. Calculate A + B. Is there overflow, underflow, or neither?AB
a.216255
b.185122
a.) The first step is to convert from decimal to binary, then Add A to B
A 216B 255
110110001111111
A11011000
+B1111111
=101010111
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow by many, but in this textbook, that is considered an overflow." (given by the book) There is underflow
b.) The first step is to convert from decimal to binary, then subtractA 185B 122
1011100101111010
A10111001
-B01111010
=100110011
"Underflow occurs when a number is too small to be representedcorrectlya negative result when doing unsigned arithmetic, for example. (Thecase when a positive result is generated by the addition of two negative integers isalso referred to as underflow" (given by the book)There is overflow
3.3.3 Assume A and B are signed 8-bit decimal integers stored in sign magnitudeformat. Calculate A B. Is there overflow, underflow, or neither?
AB
a.216255
b.185122
a.) The first step is to convert from decimal to binary, then Add A to B
A 216B 255
1101100001111111
A11011000
-B01111111
=101010111
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow by many, but in this textbook, that is considered an overflow.(given by the book) There is neitheroverflow, nor underflow
b.) The first step is to convert from decimal to binary, then subtractA 185B 122
1011100101111010
A10111001
-B01111010
=00111111
"Underflow occurs when a number is too small to be representedcorrectlya negative result when doing unsigned arithmetic, for example. (Thecase when a positive result is generated by the addition of two negative integers isalso referred to as underflow" (given by the book)There is neitheroverflow, nor underflow
3.3.4 Assume A and B are signed 8-bit decimal integers stored intwos complement format. Calculate A + B using saturating arithmetic. The resultshould be written in decimal. Show your work.
AB
a.15139
b.151214
a.) The first step is to convert from decimal to binary, Then take the 2s complement and Add 1, A 15B 139
0000111110001011
2s complement1111000001110100
+ 11111000101110101
Then A + BA 11110001
+B01110101
=01100110
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow" (given by the book)There is neitheroverflow, nor underflow
b.)The first step is to convert from decimal to binary, Then take the 2s complement and Add 1, A 151B 214
1001011111010110
2s complement0110100000101001
+ 10110100100101010
Then A + BA 01101001
+B00101010
=10010010
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow"(given by the book)There is overflow because the sum of two positive numbers gives a negative number.
3.3.5 Assume A and B are signed 8-bit decimal integers stored intwos complement format. Calculate A B using saturating arithmetic. The resultshould be written in decimal. Show your work.
a.) The first step is to convert from decimal to binary, Then take the 2s complement and Add 1, A 15B 139
0000111110001011
2s complement1111000001110100
+ 11111000101110101
Then A - BA 11110001
-B01110101
=01111100
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow" (given by the book)There is overflow
b.)The first step is to convert from decimal to binary, Then take the 2s complement and Add 1, A 151B 214
1001011111010110
2s complement0110100000101001
+ 10110100100101010
Then A - BA 01101001
-B00101010
=00111110
"Underflow occurs when a number is too small to be represented correctlya negative result when doing unsigned arithmetic, for example. (The case when a positive result is generated by the addition of two negative integers is also referred to as underflow"(given by the book)There is underflow