0

how can I divide a binary number (in 2 complement) by 2 .
I've tried bit shifting but I have a problem with negative odd numbers, how can I solve it? for example :

(-7/2) 11001/2 => (shifts the number one place to the right) => 11100 (-4)
4

1 回答 1

0

Can you use after the . ? Like this?

        1 0011 . 1000
Part    1 2    3 4

Part 1: Negative number
Part 2: Makes 3
Part 3: Separate by .
part 4: Makes 0.5

The negative part works like:

.1000 = 0.5
.0100 = 0.25
.1100 = 0.75
.0010 = 0.125

So instead of multiply by 2 to shift to left. You can do a divide by 2 to the right. So after the dot /2 and before the dot x2.

Hope you can use this information.

于 2012-12-10T15:44:38.880 回答