Reputation: 21
I've been searching around the web for a solution for this question for several weeks but without any success.
My University professor told me that to convert a binary number with a fractional part to a negative number in Two's complement we must do this:
1)Convert the number from base 10 to base 2 (+4.25) = (0100.0100)
2)The only part we need to convert in two's complement right now is the part before the point.
0100 -> 1011 -> 1011 + 1 -> 1100
So for him, -4.25 in two's complement is (1100.0100) without any conversion for the fractional part.
For me, this solution is wrong because if we try to add up these two numbers we get
0100.0100 + 1100.0100 = 0000.1000
that's 0.5 not 0
Upvotes: 0
Views: 2654
Reputation: 103
Your professor is simply wrong.
This statement refers to a negative value with a fractional part: "The two’s complement representation is formed by inverting the bits of the absolute value and adding a 1 to the least significant (rightmost) bit."
Moreover, Fixed-Point is usually stored in microprocessors as integers, where you as a programmer must know where the point is and where it moves (e.g. in multiplications). The CPU does not know it is a fixed point value and treats it as an integer.
Upvotes: 1
Reputation:
For a fraction you do exactly the same as a normal integer, meaning invert all the bits and +1 to the Least significant bit for your representation:
4.25 = 0100.0100
-4.25 = 1011.1100
Also can't come up with anything your professor could have meant.
Upvotes: 2