Microprocessor Question -- ALU operations

  • Thread starter Thread starter jaus tail
  • Start date Start date
  • Tags Tags
    Alu Operations
Click For Summary
The discussion revolves around understanding 2's complement representation and the process of dividing a negative binary number by two. Participants clarify that dividing a negative number in 2's complement should maintain its negative value, and the result should also be in 2's complement form. There is confusion regarding the conversion steps, particularly in obtaining the original number from its 2's complement and the implications of right shifting. The importance of the most significant bit (MSB) in determining the sign of the number is emphasized, with participants sharing strategies for handling binary arithmetic. Overall, the conversation highlights the complexities of binary operations and the need for practice to master these concepts.
jaus tail
Messages
613
Reaction score
48

Homework Statement


upload_2017-12-17_17-9-15.png
[/B]

Homework Equations


Division by two means moving the bits right by 1 unit.
2's complement = 1's complement + 1

The Attempt at a Solution


For Question: 6
Number is 11010110 This is 2's complement.
So to find original number we subtract by 1 and get: 11010101
Now we do 1's complement to get original number: 00101010
Now we move right by 1 bit and get: 00010101

But book says answer is D
Where am I wrong?
 

Attachments

  • upload_2017-12-17_17-9-15.png
    upload_2017-12-17_17-9-15.png
    12.5 KB · Views: 1,042
Physics news on Phys.org
If you divide a negative number by 2, the quotient is a negative number. Since 2s compliment numbers represent negative, the result should be in 2s compliment form
 
  • Like
Likes jaus tail
jaus tail said:
For Question: 6
Number is 11010110 This is 2's complement.
So to find original number we subtract by 1 and get: 11010101 This is where I think you are wrong
Now we do 1's complement to get original number: 00101010
Now we move right by 1 bit and get: 00010101

But book says answer is D - Where am I wrong?
You know you are wrong, because you start with a negative number, divide by +2 and end up with a positive number.

I think you have wrongly reversed the trick for making numbers into 2's comp.
 
  • Like
Likes jaus tail
jaus tail said:
For Question: 6
Number is 11010110 This is 2's complement.
Is this binary string representing a positive number or a negative number?
 
Thanks. I took 2's complement of number, did rotate by 1 to right side of each bit and then again took 2's complement and that gave me the answer.
So 2's complement of:
110110110
first do minus 1
So I get:
110110110
- 00000001
= 11010101

Now I do 1's complement of this and get:
00101010
Now rotate by 1 bit right side and this becomes
00101010
to
00010101
Now first take 1's complement
00010101
becomes
11101010
Now take 2's complement means add +1 and this becomes
11101011
This is answer. Thanks. But this is horrible. In exam I'd get stuck somewhere. There is so much to remember.
How to solve the next part?
I don't even know how to start?
Carry Bit is 0. Does 1's complemet or 2's complement change that?

But how to solve the next question. Book answer is A. I
 
NascentOxygen said:
Is this binary string representing a positive number or a negative number?

I think it's negative number because MSB is 1
For positive number the 1's complement and 2's complement is same number.
Like: +4 = 0100
It's 1's complement and 2's complement is 0100
I checked on google.
 
jaus tail said:
I think it's negative number because MSB is 1
So once you've determined that number, don't forget to show its negative sign.
 
  • Like
Likes jaus tail
jaus tail said:
... But this is horrible. In exam I'd get stuck somewhere. There is so much to remember.
Yeah, I know how you feel. If you do it a lot, it will become easy like common arithmetic. But I don't. I'm no good at maths, so I just remember how the numbers work and use column values.
So for 8 bits, MSB is worth -128 and the other 7 bits, +64,+32 ..., +1. (Then you could just do the arith in denary if you like!)

But to think of the binary; say you had -108 for eg. That would be -128 +16 +4 or 1001 0100
Now if you want that divided by 2 (to get -54) you could have that as -64 +8 +2 because that is half of all the column values.

But in 8bit 2's comp only the MSB is negative. So we replace that -64 with -128 +64 and our result is then -128 +64 +8 +2 or 1100 1010
What you've done is to simply shift the 2's comp right 1 bit, as you might expect for div by 2, but keep the MSB at 1

Any time you have a 2's comp negative number, MSB is 1 and Rshift moves it to be half the value but positive instead of negative. So long as the MSB is replaced with another 1, the total of these two becomes half the MSB value but negative.

If the 2's comp is a positive number, MSB is 0 and R shifting it means it is still 0. If we keep the MSB as 0, then nothing has changed here, but all the positive values have moved down 1 bit and are half their value as required.
2sComp.png


Once you've got your correct result, by whatever means, you can see how the bits move. Then it's easy to decide which shift operations do the job.
Remember they've mentioned the carry bit (which is often ignored), so that probably gets used here.
 

Attachments

  • 2sComp.png
    2sComp.png
    2.6 KB · Views: 412
  • Like
Likes jaus tail
Thanks for all the replies.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
9
Views
36K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
3K