Sunteți pe pagina 1din 14

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 8 into binary numbers.
A
B
3
1
7
4
0
5
2
2
011
001
111
100
000
101
010
010
So in Binary A: 011 001 111 100two and B: is 000 101 010 010two
A
011
001
111
100
+B
000
101
010
010
=
011
111
001
110
The binary sum of A and B is 011 111 001 110 two, in octal it is 3716.
b.) Well do the same thing as in a)
A
B
4
1
6
5
1
6
5
4
100
001
110
101
001
110
101
100
So the binary representation of A: 100 001 110 101 two and B: 001 110 101 100two.
A
100
001
110
101
+B
001
110
101
100
=
110
000
100
001
The binary sum of A and B is 110 000 100 001 two, 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.
In computer science, the sign bit is a bit in a signed number representation that
indicates the sign of a number. Only signed numeric data types have a sign bit, and
its place is usually the leftmost, where the most significant bit in unsigned numbers
resides. Floating point numbers in IEEE format are always signed, with the sign bit in
the leftmost position. Typically if the sign bit is 1 then the number is negative (in the
case of twos complement integers) or non-positive (for ones
complement integers, sign-and-magnitude integers, 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.1
a.)
A
B
3
1
7
4
0
5
2
2
011
001
111
100
000
101
010
010

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 100 two and B: 000 101
010 010two.
A
011
001
111
100
+B
000
101
010
010
=
011
111
001
110
The binary sum of A and B is 011 111 001 110 two, in octal it is 3716.
b.) Well start off the same way as above by converting the octal into binary.
A
B
4
1
6
5
1
6
5
4
100
001
110
101
001
110
101
100
In A the most significant bit is 1, so it is negative. Leave the most significant bit
which is the 1, which leaves you with:
00
001
110
101
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
11
110
001
010
Take that and add 1 to it:
11
110
001
010
+1
11
110
001
011
B is the same as before, since the number is positive.
B
1
6
5
4
001
110
101
100
The binary representation of A is 11 110 001 011 two, and B is 001 110 101 100two.
The sum of A and B is:
A2
11
110
001
011
+B
001
110
101
100
=
01
100
110
111
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.
A
B
a.)
7040
0444
b.)
4365
3412
a.) The first step is the same as 3.1.1 and 3.1.2, convert to binary:
A
B
7
0
4
0
0
4
4
4
111
000
100
000
000
100
100
100
A B:
A
111
000
100
000

-B
000
100
100
100
=
110
011
111
100
110 011 111 100two, which is 6374 octal.
b.) Again convert the octal into binary:
A
4
3
6
5
3
100
011
110
101
011
A B:
A
110
011
110
101
-B
011
100
001
010
=
000
111
101
011
= 000 111 101 011_two, which is 0753 octal.

B
4
100

1
001

2
010

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.) Since A is negative you are going to do steps similar to problem 3.1.2, drop the
most significant bit giving you 11 000 100 000 two, 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
7
0
4
0
111
000
100
000
Drop the most
significant bit
11
000
100
000
Switch 0s and 1s
00
111
011
111
2s complement
00
111
100
000
B is the same as before, since the number is positive.
B
0
4
4
4
000
100
100
100
Now do A B:
A
00
111
100
000
-B
000
100
100
100
=
00
010
111
100
00 010 111 100two is 0274 octal.
b.) Since A is negative you are going to do steps similar to problem 3.1.2, drop the
most significant bit giving you 00 011 110 101 two, 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
4
3
6
5

100
011
110
101
Drop the most significant bit
00
011
110
101
Switch 0s and 1s
11
100
001
010
2s complement
11
100
001
011
B is the same as before, since the
B
3
4
1
2
011
100
001
010
AB
A
11
100
001
-B
011
100
001
=
00
000
000
00 000 000 001two is 0001 octal.
Exercise 3.2
A
B
a.
1446
672F
b.
2460
4935

number is positive.

011
010
001

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
1
4
4
6
6
7
2
F
0001
0100
0100
0110
0110
0111
0010
1111
A+B
A
0001
0100
0100
0110
+B
0110
0111
0010
1111
=
0111
1011
0111
0101
Now you want to convert 0111 1011 0111 0101 back into hexadecimal.
0111
1011
0111
0101
7
B
7
5
A + B = 7B75

b.) Again convert the hexadecimal numbers into binary.


A
2
4
6
0
4
9
0010
0100
0110
0000
0100
1001
A+B
A
0010
0100
0110
0000
+B
0100
1001
0011
0101
=
0110
1101
1001
0101

B
3
0011

5
0101

Now take 0110 1101 1001 0101 and convert it back into hexadecimal.
0110
1101
1001
0101
6
D
9
5
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 work
A
B
a.
1446
672F
b.
2460
4935
a.)The first step is to convert from hexadecimal to binary.

1
0001

4
0100

A
4
0100

6
0110

6
0110

7
0111

B
2
0010

F
1111

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 unsigned 16 -bits.
A in binary
B
A+B (binary)
A+B = 7b75

0001
0110
0111

0100
0111
1011

0100
0010
0111

0110
1111
0101

b.)The first step is to convert from hexadecimal to binary.


A
2
4
6
0
4
9
0010
0100
0110
0000
0100
1001

B
3
0011

5
0101

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 unsigned 16 -bits.
A in binary

001

010

011

000

B
A+B (binary)

0
010
0
011
0

0
100
1
110
1

0
001
1
100
1

0
010
1
010
1

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.
b.

A
1446
2460

Unsigned Format:
a.) The value of A which is 1446 (base 16) that can be represented in a binary form
(base 2) by
A
1
4
4
6
0001
0100
0100
0110
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

2
0010

4
0100

6
0110

0
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:
a.)The value of A which is 1446 (base 16) that can be represented in a binary form
(base 2) by
A
1
4
4
6
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).
b.)
The value of A is 2460 (base 16) which can be represented in a binary form (base 2)
by
A
2
4
6
0
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).
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.

a.
b.

A
C352
5ED4

B
36AE
07A4

a.) The first step is to convert from hexadecimal to binary. Then subtract A to B
A
C
3
5
2
B
3
6
A
E
1100
0011
0101
0010
0011 0110 1010 1110

A-B =

1100
0011
1000

0011
0110
1100

0101
1010
1010

0010
1110
0100

A-B= 8CA4
b.) The first step is to convert from hexadecimal to binary. Then subtract A to B
A
5
E
D
4
B
0
7
A
4
0101
1110
1101
0100
0000 0111 1010 0100

A-B =

0101
0000
0101

1110
0111
0111

1101
1010
0011

0100
0100
0000

A-B=5730
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
hexadecimal. Show your work.
A
B

a.
b.

C352
5ED4

36AE
07A4

a.) The first step is to convert from hexadecimal to binary


A
C
3
5
2
B
3
6
A
E
1100
0011 0101
0010
0011
0110
1010
1110
Since A 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 result
0011
1100
1010
1101
+1
0011
1100
1010
1110
B is the same as before, since the number is positive.
A
B
A-B =
A-B=0600

0011

1100

1010

1110

0011
0000

0110
0110

1010
0000

1110
0000

b.) The first step is to convert from hexadecimal to binary


A

5
0101

E
1110

D
1101

4
0100

0
0000

7
0111

A
1010

4
0100

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 unsigned 16 -bits.
A
0101 1110 1101 0100
B
0000 0111 1010 0100
A-B =
0101 0111 0011 0000
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 is C352 (base 16) that can be represented in a binary form
(base 2) by
A
C
3
5
2
1100
0011
0101
0010
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 is 5ED4 (base 16) which can be represented in a binary form
(base 2) by
A
5
E
D
4
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
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.) The following table shows pairs of decimal numbers.

a.
b.

A
216
185

B
255
122

3.3.1 Assume A and B are unsigned 8-bit decimal integers. Calculate


A B. Is there overflow, underflow, or neither?
a.) The first step is to convert from decimal to binary, then subtract
A

216
11011000

A
-B
=

11011000
1111111
1100111

255
1111111

"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 subtract
A
185
B
122
10111001
1111010
A
-B
=

10111001
1111010
00111111

"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, 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
magnitude
format. Calculate A + B. Is there overflow, underflow, or neither?
A
B
a.
216
255
b.
185
122
a.) The first step is to convert from decimal to binary, then Add A to B
A

216
11011000

A
+B
=

11011000
1111111
101010111

255
1111111

"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 subtract
A
185
B
122
10111001
01111010
A
-B

10111001
01111010

100110011

"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
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?

a.
b.

A
216
185

B
255
122

a.) The first step is to convert from decimal to binary, then Add A to B
A

216
11011000

A
-B
=

11011000
01111111
101010111

255
01111111

"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 neither overflow, nor underflow
b.) The first step is to convert from decimal to binary, then subtract
A
185
B
122
10111001
01111010
A
-B
=

10111001
01111010
00111111

"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 neither overflow, nor underflow
3.3.4 Assume A and B are signed 8-bit decimal integers stored in
twos complement format. Calculate A + B using saturating arithmetic.
The result
should be written in decimal. Show your work.

a.
b.

A
15
151

B
139
214

a.) The first step is to convert from decimal to binary, Then take the 2s complement
and Add 1,
A
15
B
139
00001111
10001011
2s
11110000
01110100
complement
+1
11110001
01110101

Then A + B
A
11110001
+B
01110101
=
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 neither overflow, nor underflow
b.) The first step is to convert from decimal to binary, Then take the 2s complement
and Add 1,
A
151
B
214
10010111
11010110
2s
01101000
00101001
complement
+1
01101001
00101010
Then A + B
A
01101001
+B
00101010
=
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 in
twos complement format. Calculate A B using saturating arithmetic. The
result
should 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
15
B
139
00001111
10001011
2s
11110000
01110100
complement
+1
11110001
01110101
Then A - B
A
11110001
-B
01110101
=
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
151
B
214
10010111
11010110
2s
01101000
00101001
complement
+1
01101001
00101010
Then A - B
A
01101001
-B
00101010
=
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

S-ar putea să vă placă și