# Homework Help: Microprocessor Question -- ALU operations

1. Dec 17, 2017

### jaus tail

1. The problem statement, all variables and given/known data

2. Relevant equations
Division by two means moving the bits right by 1 unit.
2's complement = 1's complement + 1
3. 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?

2. Dec 17, 2017

### scottdave

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

3. Dec 17, 2017

### Merlin3189

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.

4. Dec 17, 2017

### Staff: Mentor

Is this binary string representing a positive number or a negative number?

5. Dec 17, 2017

### jaus tail

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

6. Dec 17, 2017

### jaus tail

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

7. Dec 17, 2017

### Staff: Mentor

So once you've determined that number, don't forget to show its negative sign.

8. Dec 17, 2017

### Merlin3189

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.

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.

9. Dec 18, 2017

### jaus tail

Thanks for all the replies.