++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
Since the most left bit is the sign bit in the binary number
(only having 0s, or 1s), then the following rule will be used on any binary number in order to figure out either the given number is a positive number or a negative number:
1-If the most left bit is o, 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.
The value of A which is 3174 (base 8) that can be
represented in a binary form (base 2) by
The value of B is 0522 (base 8) that can be represented in a
binary form (base 2) by
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 for
adding A+B in unsigned 12 -bits .
The value of A is 4165 (base 8) which can be represented in
a binary form (base 2) by
The value of B is 1654(base 8) which can be represented in a
binary form (base 2) by
B has a zero at most
left bit, and then it is a positive number (we do nothing).
However, A has one at the most left bit then it is a
negative number .In order to treat A as a positive number we need to use the
2’s complement.
By converting 0s to
ones and ones to zeros in the binary
format then add 1 to it. As a result of that we will get a
positive number. instead of a negative number in order to do arithmetic operations in a
CPU.
The value of A which is 4165 (base 8) that can be
represented in a binary form (base 2) by
Also, we can solve A-B by finding the 2’s complement of B
.Then we can do the arithmetic operation, which will be the sum of A+ 2'complement of B.
By converting 0s to
ones and ones to zeros in the binary
number then add 1 to it,we will get a
positive number instead of a negative number in order to do arithmetic operation in a
CPU.
The value of B is 0444 (base 8) which can be represented in
a binary form (base 2) by
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A has one at the most left bit then it is a negative number
.In order to treat A as a positive number we need to use the 2’s complement.
By converting 0s to
ones and ones to zeros in the binary
number then add 1,we will get a
positive number instead of a negative number in order to do arithmetic operation in a
CPU.
However, B has a zero at most left bit, and then it is a
positive number (we do nothing).
A has one at the most left bit then it is a negative number
.In order to treat A as a positive number we need to use the 2’s complement.
By converting 0s to
ones and ones to zeros in the binary
number then add 1,we will get a
positive number instead of a negative number in order to do arithmetic operation in a
CPU.
However, B has a zero at most left bit, and then it is a
positive number (we do nothing).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.1.6 Convert A into a binary number. What makes base 8 (octal) an attractive numbering system for representing values in computers?
Answer:
A
a. 7040
b. 4365
A in octal
|
7
|
0
|
4
|
0
|
A in binary
|
111
|
000
|
100
|
|
then converting the binary number to decimal number by the following way:
starting from the right to the left (from zero to 11 as power of base 2 multiplying by its binary bit then adding the value to the next one )
(0* 2^0) + (0* 2^1)+(0* 2^2)+(0* 2^3)+(0* 2^4)+(1* 2^5)+(0* 2^6)+(0* 2^7)+(0* 2^8)+(1* 2^9)+
(1* 2^10)+(1* 2^11) = 32++512+1024 +2048= 3616 (base 10).
part(b)
A in octal
|
4
|
3
|
6
|
5
|
A in binary
|
100
|
011
|
110
|
|
(1* 2^0) + (0* 2^1)+(1* 2^2)+(0* 2^3)+(1* 2^4)+(1* 2^5)+(1* 2^6)+(1* 2^7)+(0* 2^8)+(0* 2^9)+
(0* 2^10)+(1* 2^11) = 1+4+16+32+64+128 +2048= 2293 (base 10).
____________________________________________________________________
_____________________________________________________________________
Exercise 3.2
Hexadecimal (base 16) is also a commonly used numbering system for representing
values in computers. In fact, it has become much more popular than octal. The
following table shows pairs of hexadecimal numbers.
A B
a. 1446 672F
b. 2460 4935
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.
Answer:
The following table is used to converting from hexadecimal number (base 16) to binary number(base 2) and vice- versa .Every hexadecimal number is represented by 4-bits.
The binary- hexadecimal conversion table:
Binary (base 2)
|
Hexadecimal
(base 16)
|
0
|
0
|
0
|
0
|
zero
|
0
|
0
|
0
|
1
|
one
|
0
|
0
|
1
|
0
|
two
|
0
|
0
|
1
|
1
|
three
|
0
|
1
|
0
|
0
|
four
|
0
|
1
|
0
|
1
|
five
|
0
|
1
|
1
|
0
|
sex
|
0
|
1
|
1
|
1
|
seven
|
1
|
0
|
0
|
0
|
eight
|
1
|
0
|
0
|
1
|
nine
|
1
|
0
|
1
|
0
|
A
|
1
|
0
|
1
|
1
|
B
|
1
|
1
|
0
|
0
|
C
|
1
|
1
|
0
|
1
|
D
|
1
|
1
|
1
|
0
|
E
|
1
|
1
|
1
|
1
|
F
|
Unsigned 16-bit hexadecimal numbers
part(a)
A B
a. 1446 672F
The following table shows the operations that are needed to get the required solution.
In order to get the sum of A+b in hexadecimal base, we need several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2) into (A+B)(base 16) or in hexadecimal number.
A in hexadecimal
| 1 |
4
|
4
|
6
|
Label
|
Comment
|
A in binary
| 0001 | 0100 | 0100 | 0110 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B in hexadecimal
| 6 |
7
| 2 | F |
|
|
B
| 0110 | 0111 | 0010 | 1111 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A+B (binary)
| 0111 | 1011 | 0111 | 0101 |
①+②
In binary
|
adding①+② in order to get the sum of A+B in binary form
|
A+B (hexadecimal)
|
7
|
b
| 7 | 5 |
①+②
In
hexadecimal.(base 16)
|
Converting the sum of A+B from binary form( base 2) to hexadecimal. form(base 16)
|
Unsigned 16-bit hexadecimal numbers
part(b)
A B
b. 2460 4935
The following table shows the operations that are needed to get the required solution.
In order to get the sum of A+b in hexadecimal base, we need several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A+B)(base 2).
4-Converting (A+B)(base 2) into (A+B)(base 16) or in hexadecimal number.
A in hexadecimal
| 2 |
4
|
6
|
0
|
Label
|
Comment
|
A in binary
| 0010 | 0100 | 0110 | 0000 |
…①
|
Converting the number from hexadecimal.number to binary number(base 2)
|
B in hexadecimal
| 4 |
9
| 3 | 5 |
|
|
B
| 0100 | 1001 | 0011 | 0101 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A+B (binary)
| 0110 | 1101 | 1001 | 0101 |
①+②
In binary
|
adding①+② in order to get the sum of A+B in binary form
|
A+B (hexadecimal)
|
6
|
d
| 9 | 5 |
①+②
In
hexadecimal. (base 16)
|
Converting the sum of A+B from binary form( base 2) to hexadecimal. form(base 16)
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.2.2 What is the sum of A and B if they represent signed 16-bit hexa- decimal numbers stored in sign-magnitude format? The result should be written in hexadecimal. Show your work
Answer:
Signed 16-bit hexadecimal numbers stored in sign-magnitude format
part(a)
A B
a. 1446 672F
Since the left bit is the sign bit in the binary number (only having 0s, or 1s), 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.
By applying this rule on part (a), then
The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by
______________________________________________________
The value of B is 672F (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
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 for adding A+B in unsigned 16 -bits.
A in hexadecimal
| 1 |
4
|
4
|
6
|
Label
|
Comment
|
A in binary
| 0001 | 0100 | 0100 | 0110 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B in hexadecimal
| 6 |
7
| 2 | F |
|
|
B
| 0110 | 0111 | 0010 | 1111 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A+B (binary)
| 0111 | 1011 | 0111 | 0101 |
①+②
In binary
|
adding①+② in order to get the sum of A+B in binary form
|
A+B (hexadecimal)
|
7
|
b
| 7 | 5 |
①+②
In
hexadecimal.
(base 16)
|
Converting the sum of A+B from binary form( base 2) to hexadecimal. form(base 16)
|
signed 16-bit hexadecimal numbers stored in sign-magnitude format
part(b)
A B
b. 2460 4935
Since the left bit is the sign bit in the binary number (only having 0s, or 1s), 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.
By applying this rule on part (a), then
The value of A which is 2460 (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
The value of B is 4935 (base 16) that can be represented in a binary form (base 2) by
_____________________________________________________
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 for adding A+B in unsigned 16 -bits.
A in hexadecimal
| 2 |
4
|
6
|
0
|
Label
|
Comment
|
A in binary
| 0010 | 0100 | 0110 | 0000 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B
| 4 |
9
| 3 | 5 |
|
|
B
| 0100 | 1001 | 0011 | 0101 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A+B (binary)
| 0110 | 1101 | 1001 | 0101 |
①+②
In binary
|
adding①+② in order to get the sum of A+B in binary form
|
A+B (hexadecimal)
|
6
|
d
| 9 | 5 |
①+②
In
hexadecimal.(base 16)
|
Converting the sum of A+B from binary form( base 2) to hexadecimal. form(base 16)
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.2.3 Convert A into a decimal number, assuming it is unsigned.
Repeat assuming it stored in sign-magnitude format. Show your work.
Answer:
Unsigned
A
a. 1446
b. 2460
part(a)
The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by
A in hexadecimal
|
1
|
4
|
4
|
6
|
A in binary
|
0001
|
0100
|
0100
|
0110
|
then converting the binary number to decimal number by the following way:
starting from the right to the left (from zero to 15 as power of the base 2 multiplying by its binary bit then adding the value to the next one )
(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).
part(b)
The value of A is 2460 (base 16) which can be represented in a binary form (base 2) by
A in hexadecimal
|
2
|
4
|
6
|
0
|
A in binary
|
0010
|
0100
|
0110
|
0000
|
(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:
The value of A which is 1446 (base 16) that can be represented in a binary form (base 2) by
A in hexadecimal
|
1
|
4
|
4
|
6
|
A in binary
|
0001
|
0100
|
0100
|
0110
|
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).
part(b)
The value of A is 2460 (base 16) which can be represented in a binary form (base 2) by
A in hexadecimal
|
2
|
4
|
6
|
0
|
A in binary
|
0010
|
0100
|
0110
|
0000
|
(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).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The following table also shows pairs of hexadecimal numbers.
A B
a. C352 36AE
b. 5ED4 07A4
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.
Answer:
unsigned 16-bit hexadecimal numbers
part(a):
A B
a. C352 36AE
The following table shows the operations that are needed to get the required solution.
In order to get the result of A-b in hexadecimal base, we need several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A-B)(base 2).
4-Converting (A-B)(base 2) into (A-B)(base 16) or in hexadecimal number.
A in hexadecimal
| C |
3
|
5
|
2
|
Label
|
Comment
|
A in binary
| 1100 | 0011 | 0101 | 0010 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B in hexadecimal
| 3 |
6
| A | E |
|
|
B
| 0011 | 0110 | 1010 | 1110 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A-B (binary)
| 1000 | 1100 | 1010 | 0100 |
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
A-B (hexadecimal)
|
8
|
C
| A | 4 |
①-②
In
hexadecimal.
(base 16)
|
Converting the result of A-B from binary form( base 2) to hexadecimal. form(base 16)
|
unsigned 16-bit hexadecimal numbers
part(b):
A B
b. 5ED4 07A4
The following table shows the operations that are needed to get the required solution.
In order to get the result of A-b in hexadecimal base, we need several procedures;
1-Converting A (base 16) into A (base 2) by using the hexadecimal-binary conversion table.
2-Converting B (base 16) into B (base 2) by using the hexadecimal-binary conversion table.
3-Doing the arithmetic operations (A-B)(base 2).
4-Converting (A-B)(base 2) into (A-B)(base 16) or in hexadecimal number.
A in hexadecimal
| 5 |
E
|
D
|
4
|
Label
|
Comment
|
A in binary
| 0101 | 1110 | 1101 | 0100 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B
in hexadecimal
| 0 |
7
| A | 4 |
|
|
B
| 0000 | 0111 | 1010 | 0100 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A-B (binary)
| 0101 | 0111 | 0011 | 0000 |
①-②
In binary
|
subtracting ①-②of A-B in binary form
|
A-B (hexadecimal)
|
5
|
7
| 3 | 0 |
①-②
In hexadecimal.
(base 16)
|
Converting the result of A-B from binary form( base 2) to hexadecimal. form(base 16)
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.2.5 What is A – B if they represent signed 16-bit hexadecimal numbers stored in sign-magnitude format? The result should be written in hexa- decimal. Show your work.
Answer:
signed 16-bit hexadecimal numbers
part(a)
A B
a. C352 36AE
Since the left bit is the sign bit in the binary number (only having 0s, or 1s), 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.
By applying this rule on part (a), then
A in hexadecimal
|
C
|
3
|
5
|
2
|
A in binary
|
1100
|
0011
|
0101
|
|
A has one at the most left bit then it is a negative number .In order to treat A as a positive number we need to use the 2’s complement.
By converting 0s to ones and ones to zeros in the binary number then add 1,we will get a positive number instead of a negative number in order to do arithmetic operation in a CPU.
After converting, we get
Then adding 1, we get
0011
|
1100
|
1010
|
1110
|
3
|
C
|
A
|
E
|
By using the octal table, we can get the value of A in the octal form
A= 3CAE (base 16)
However, B has a zero at most left bit, and then it is a positive number (we do nothing).
A in hexadecimal
| 3 |
C
|
A
|
E
|
Label
|
Comment
|
A in binary
| 0011 | 1100 | 1010 | 1110 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B
| 3 |
6
| A | E |
|
|
B
| 0011 | 0110 | 1010 | 1110 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A-B (binary)
| 0000 | 0110 | 0000 | 0000 |
①-②
In binary
|
subtracting ①-② in order to get the sum of A-B in binary form
|
A-B (hexadecimal)
|
0
|
6
| 0 | 0 |
①-②
In
hexadecimal.
(base 16)
|
Converting the result of A-B from binary form( base 2) to hexadecimal. form(base 16)
|
signed 16-bit hexadecimal numbers
part(B):
A B
b. 5ED4 07A4
By applying this rule on part (b), then
The value of A which is 5ED4 (base16) that can be represented in a binary form (base 2) by
______________________________________________________
The value of B is 07A4 (base16) that can be represented in a binary form (base 2) by
_____________________________________________________
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 result of A-B in singed 12-bits will be similar for subtracting A-B in unsigned 16 -bits.
A in hexadecimal
| 5 |
E
|
D
|
4
|
Label
|
Comment
|
A in binary
| 0101 | 1110 | 1101 | 0100 |
…①
|
Converting the number from hexadecimal.base to binary number(base 2)
|
B
| 0 |
7
| A | 4 |
|
|
B
| 0000 | 0111 | 1010 | 0100 |
…②
|
Converting the number from hexadecimal. base to binary number(base 2)
|
A-B (binary)
| 0101 | 0111 | 0011 | 0000 |
①-②
In binary
|
adding①-② in order to get the result of A-B in binary form
|
A-B (hexadecimal)
|
5
|
7
| 3 | 0 |
①-②
In hexadecimal.
(base 16)
|
Converting the result of A-B from binary form( base 2) to hexadecimal. form(base 16)
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
Answer:
part(a)
The value of A which is C352 (base 16) that can be represented in a binary form (base 2) by
A in hexadecimal
|
C
|
3
|
5
|
2
|
A in binary
|
1100
|
0011
|
0101
|
0010
|
then converting the binary number to decimal number by the following way:
starting from the right to the left (from zero to 15 as power of the base 2 multiplying by its binary bit then adding the value to the next one )
(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).
part(b)
The value of A is 5ED4 (base 16) which can be represented in a binary form (base 2) by
A in hexadecimal
|
5
|
E
|
D
|
4
|
A in binary
|
0101
|
1110
|
1101
|
0100
|
(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.3
Overflow occurs when a result is too large to be represented accurately given a
finite word size. Underflow occurs when a number is too small to be represented
correctly—a 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.) The following table shows pairs of decimal numbers.
A B
a. 216 255
b. 185 122
3.3.1 Assume A and B are unsigned 8-bit decimal integers. Calculate
A – B. Is there overflow, underflow, or neither?
part(a):
A B
a. 216 255
A in decimal
|
216
|
Label
|
Comment
|
A in binary
|
11011000
|
…①
|
Converting the number
from decimal base to binary number(base 2)
|
B in decimal
|
255
|
|
|
B in binary
|
1111111
|
…②
|
Converting the number
from decimal. base to binary number(base 2)
|
A-B (binary)
|
-100111
the minus sign will be replaced by one, then we have
1100111
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
According to the this description "Underflow occurs when a number is too small to be represented
correctly—a 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. " that is given by the question ,
There is underflow
|
part(b)
A B
b. 185 122
A in decimal
|
185
|
Label
|
Comment
|
A in binary
|
10111001
|
…①
|
Converting the number from decimal base to binary number(base 2)
|
B in decimal
|
122
| | |
B in binary
|
1111010
|
…②
|
Converting the number from decimal. base to binary number(base 2)
|
A-B (binary)
|
00111111
it is positive and small number
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
According to the this description "Underflow occurs when a number is too small to be represented
correctly—a 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 " that is given by the question ,
There is underflow
However,t in this textbook, it is considered as an overflow.
two negative numbers give a positive number
|
3.3.2 Assume A and B are signed 8-bit decimal integers stored in sign magnitude
format. Calculate A + B. Is there overflow, underflow, or neither?
part(a):
A B
a. 216 255
A in decimal
|
216
|
Label
|
Comment
|
A in binary
|
11011000
|
…①
|
Converting the number from decimal base to binary number(base 2)
|
B in decimal
|
255
| | |
B in binary
|
1111111
|
…②
|
Converting the number from decimal. base to binary number(base 2)
|
A+B (binary)
|
101010111
we got nine bits instead of 8-bits ,so more bit than should we have and the result is a negative number
|
①+②
In binary
|
adding①+② in order to get the sum of A+B in binary form
|
There is overflow
|
part(b)
A B
b. 185 122
A in decimal
|
185
|
Label
|
Comment
|
A in binary
|
10111001
|
…①
|
Converting the number from decimal base to binary number(base 2)
|
B in decimal
|
122
| | |
B in binary
|
1111010
|
…②
|
Converting the number from decimal. base to binary number(base 2)
|
A-B (binary)
|
100110011
we got nine bits instead of 8-bits ,so more bit than should we have and the result is a negative number
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
There is overflow
|
3.3.3 Assume A and B are signed 8-bit decimal integers stored in sign magnitude
format. Calculate A – B. Is there overflow, underflow, or neither?
part(a):
A in decimal
|
216
|
Label
|
Comment
|
A in binary
|
11011000
|
…①
|
Converting the number from decimal base to binary number(base 2)
|
B in decimal
|
255
| | |
B in binary
|
1111111
|
…②
|
Converting the number from decimal. base to binary number(base 2)
|
A-B (binary)
|
-100111
the minus sign will be replaced by one, then we have 1100111 and it is fit in 8-bits
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
It is neither overflow ,nor underflow
|
part(b)
A in decimal
|
185
|
Label
|
Comment
|
A in binary
|
10111001
|
…①
|
Converting the number from decimal base to binary number(base 2)
|
B in decimal
|
122
| | |
B in binary
|
001111010
|
…②
|
Converting the number from decimal. base to binary number(base 2)
|
A-B (binary)
|
00111111
it is positive and small number
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
It is neither overflow ,nor underflow
|
The following table also shows pairs of decimal numbers.
A B
a. 15 139
b. 151 214
3.3.4 Assume A and B are signed 8-bit decimal integers stored in
two’s complement format. Calculate A + B using saturating arithmetic. The result
should be written in decimal. Show your work.
part(a):
A B
a. 15 139
A in decimal
|
15
|
Label
|
Comment
|
A in binary
|
00001111
|
|
Converting the number
from decimal base to binary number(base 2)
|
A is signed 8-bit
decimal integers stored in
two’s complement format
|
11110000
11110001
|
…①
|
|
B in decimal
|
139
|
|
|
B in binary
|
10001011
|
|
Converting the number
from decimal. base to binary number(base 2)
|
B is signed 8-bit decimal integers stored in
two’s complement format
|
01110100
01110101
|
…②
|
|
(2’s complement of A)+( 2’s complement of B )
In binary
|
101100110
then
throw most left bit which is 1
because we have only 8-bit long
Then we have 01100110 , which is a positive number.
|
①+②
In binary
|
adding①+② in order to get the result of A+B in binary form
|
Neither overflow , nor underflow
|
part(b)
A B
b. 151 214
A in decimal
|
151
|
Label
|
Comment
|
A in binary
|
10010111
|
|
Converting the number
from decimal base to binary number(base 2)
|
A is signed 8-bit
decimal integers stored in
two’s complement format
|
01101000
01101001
|
…①
|
|
B in decimal
|
214
|
|
|
B in binary
|
11010110
|
|
Converting the number
from decimal. base to binary number(base 2)
|
B is signed 8-bit decimal integers stored in
two’s complement format
|
00101001
00101010
|
…②
|
|
(2’s complement of A)+( 2’s complement of B )
In binary
|
10010010
It is a negative number.
|
①+②
In binary
|
adding①+② in order to get the result of A+B in binary form
|
There is overflow because the sum of
two positive numbers gave a negative number.
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3.3.5 Assume A and B are signed 8-bit decimal integers stored in
two’s complement format. Calculate A – B using saturating arithmetic. The result
should be written in decimal. Show your work.
part(a):
A B
a. 15 139
A in decimal
|
15
|
Label
|
Comment
|
A in binary
|
00001111
| |
Converting the number from decimal base to binary number(base 2)
|
A is signed 8-bit decimal integers stored in
two’s complement format
|
11110000
11110001
|
…①
|
|
B in decimal
|
139
| | |
B in binary
|
10001011
| |
Converting the number from decimal. base to binary number(base 2)
|
B is signed 8-bit decimal integers stored in
two’s complement format
|
01110100
01110101
|
…②
|
|
(2’s complement of A)-( 2’s complement of B )
In binary
|
01111100
it is appositive number (24 base 10)
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
There is overflow
|
A B
b. 151 214
A in decimal
|
151
|
Label
|
Comment
|
A in binary
|
10010111
| |
Converting the number from decimal base to binary number(base 2)
|
A is signed 8-bit decimal integers stored in
two’s complement format
|
01101000
01101001
|
…①
|
|
B in decimal
|
214
| | |
B in binary
|
11010110
| |
Converting the number from decimal. base to binary number(base 2)
|
B is signed 8-bit decimal integers stored in
two’s complement format
|
00101001
00101010
|
…②
|
|
(2’s complement of A)-( 2’s complement of B )
In binary
|
00111110
It is a positive number.
|
①-②
In binary
|
subtracting①-② in order to get the result of A-B in binary form
|
There is underflow
|