Question

Computers typically do not implement integer subtraction directly, but instead using addition and negation. To accomplish...

Computers typically do not implement integer subtraction directly, but instead using addition and negation.

To accomplish negation, they often use the formula −x = (x ˆ 11 . . . 1) + 1, which can be 3 implemented using bitwise XOR and addition.

The string 11 . . . 1 here represents the all 1’s string of length n, where n is the width of the CPU.

The addition is done modulo 2n. Verify that −x ≡ (x ˆ 11 . . . 1) + 1 (mod 2n) for n = 4 and x = 3. Show your work

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let

for x = 3

-x = -3

Finding -x using negation and addition:-

given, n=4 and x = 3

representing 3 in binary 11

Since, the width of CPU is 4 ( n = 4 )

So 3 can be represented as 0011 (width is 4 by adding 2 zeros before rightmost bit does not change the notation of 3)

0011 is same as 11

the negation of 0011 is 1100 [ negation is represented as '~' , where negation means changing 0's & 1's as 1's & 0's]

and addition of 1 gives:

~0011

1100 [representing 1 as 0 & 0 as 1]

+ 1 [a simple addition]

result= 1101

Therefore, -3 is represented as 1101 using negation and addition

Finding -x using the given formula for negation:-

-x = (x^11..1) + 1

where ^ represents bitwise xor operation

and the string 11..1 here represents the all 1's string of length n, where n is the width of the CPU and also the addition is done by using modulo 2n.

finally, the formula becomes

-x = (x^11..1) + 1 (mod 2n.)

given, n=4 and x = 3

Right hand side (R.H.S) :-

x = 3 -> in binary 3 = 11

doing xor with 1111 (since n =4 , string contains 4 1's )

11 same as 0011 (preceding zeros doesn't change the number)

Truth table for xor operation:-

input 1   input 2   output
0   0   0
0   1   1
1   0   1
1   1   1
0011

^ 1111

1100 (from the truth table of xor)

+ 1 [ 1 (mod 2n.) = 1 (mod 24 ) { given, n=4}= 1 (mod 16 ) = 1 ]

result = 1101

from the formula, result = 1101

Left hand side(L.H.S) -x = -3

Since, from the result of using negation and addition -3 is equal to 1101

By equating L.H.S = R.H.S

Therefore,

-3 = 1101
Hence verified that,

-x = (x^11..1) + 1 (mod 2n.)
where the string 11..1 represents the string 11..1 of length n,

and n is the width of the CPU.

Add a comment
Know the answer?
Add Answer to:
Computers typically do not implement integer subtraction directly, but instead using addition and negation. To accomplish...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Computers typically do not implement integer subtraction directly, but instead using addition and...

    Computers typically do not implement integer subtraction directly, but instead using addition and negation. To accomplish negation, they often use the formula −x = (x ˆ 11 . . . 1) + 1, which can be 3 implemented using bitwise XOR and addition. The string 11 . . . 1 here represents the all 1’s string of length n, where n is the width of the CPU. The addition is done modulo 2n. Verify that −x ≡ (x ˆ 11...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT