Computer Science, asked by mds777, 7 months ago

Perform the arithmetic operations below with binary numbers and with negative numbers in signed

2’s complement representation. Use seven bits to accommodate each number together with its sign.

In each case, determine if there is an overflow by checking the carries into and out of the sign bit

position

(+35) + (+40)

(-35) + (-40)

(-35) – (+40)

(-35)-(-40)

(+70) +(+80)

(-70) +(-80)

(-70) -(+80)

(-70) -(-80)

(+20)+(+30)

(-20)+(-30)

(-20)-(+30)

(-20)-(-30)​

Answers

Answered by montysingh20
0

Answer:

Homework #9 KEY – answers in fuschia – 40 points total

Question 1 – Needs to say whether overflow occurred to get the 2 points for each part

1. Perform the arithmetic operations below with binary numbers and with negative numbers in signed-2’s complement representation. Use seven bits to accommodate each number together with its sign. In each case, determine if there is an overflow by checking the carries into and out of the sign bit position.

a. (+35) + (+40)

+35

0

1

0

0

0

1

1

+40

0

1

0

1

0

0

0

sum

0

1

0

0

1

0

1

1

overflow occurred because there is carry into the sign bit and no carry out

b. (-35) + (-40) should have been either (-35) + (+40) or (+35) + (-40)

+35

0

1

0

0

0

1

1

-40

1

0

1

1

0

0

0

sum

0

1

1

1

1

0

1

1

no overflow occurred because there is no carry into the sign bit and no carry out

-35

1

0

1

1

1

0

1

+40

0

1

0

1

0

0

0

sum

1

0

0

0

0

1

0

1

no overflow occurred because there is carry into the sign bit and carry out

a. (-35) + (-40)

-35

1

0

1

1

1

0

1

-40

1

0

1

1

0

0

0

sum

1

0

1

1

0

1

0

1

overflow occurred because there is no carry into the sign bit and carry out

Dividing by powers of two: Dividing by a power of 2 can be performed using right shift operations. The two different shifts – logical and arithmetic – serve this purpose for unsigned and two’s-complement numbers, respectively. Integer division always rounds towards zero. For x >= 0 and y> 0, the result should be the floor of x/y. ... For x < 0 and y > 0, the results of the integer division should be the ceiling of x/y (i.e. integer division should round negative results upwards toward zero. As we saw in class, -5/2 yielded -3 when it should have yielded -2. This can be “fixed” by “biasing” the value before shifting. We do this by adding 2k-1 to x before right shifting (where k is the number of power of 2 we are dividing by). For example, to divide -5 by 2, we first add 21-1 or 1 to x, giving us 1100, Right shifting 1 place gives us 1110 which is the two’s complement representation of -2. (information paraphrased and taken from Computer Systems, A Programmer’s Perspective, by Randal E. Bryant and David O’Hallaron.

Question 2 – 1 point for each of the 12 answers (12 points)

1. Show the largest and smallest two’s complement numbers that can be represented in each of the following number of bits and tell their decimal values

# bits

largest two’s complement

decimal equivalent

smallest two’s complement

decimal equivalent

a.

4

0111

7

1000

-8

b.

6

011111

31

100000

-32

c.

9

0111111111

255

100000000

-256

Question 3 – 1 point for each of the 15 answers (15 points) - Note, if the binary is incorrect, then take off the point

but if the octal and hex match the incorrect binary, don’t deduct further

2. What are the binary, octal, and hexadecimal representations for each of the following decimal numbers?

decimal

binary

octal

hexadecimal

a.

2347

100100101011

4453

92B

b.

98721

11000000110100001

300641

C0A1

c.

582

101000110

506

164

d.

0.5

0.1

0.4

0.8

e.

0.2

0.001100110011…

0.1463

0.333333

2347 = 2048 + ? 299

299 = 256 + ? 43

43 = 32 + 11

11 = 1011

100100101011

0.5

2

1.0

******************************

.2

2

0.4

2

0.8

2

1.6

2

1.2

2

0.4

2

0.8

3. Find and bring in a URL that explains floating point representation

if URL works, 3 points - only 1 if it’s just present but doesn’t work

4. Find and bring in a URL that explains overflow

if URL works, 3 points - only 1 if it’s just present but doesn’t work

5. Find and bring in a URL that explains underflow

if URL works, 3 points - only 1 if it’s just present but doesn’t work

Answered by mbrahmani123
0

Answer:

4679987653234678

  1. 57898765432224568900
Similar questions