09-30-2015 12:31 AM - edited 09-30-2015 12:38 AM
Hello,
I'm trying to figure out this doozie: 01 1011 - 11 1101
use 2's complement to solve, 6bits signed.
This is what I tried:
range of 6bits: -32 to 31
01 1011 = 27
11 1101 = -29
27 -(-29) = 56 (overflow)
11 1101 -- 2s complement --> 10 0011
so
01 1011
+ 10 0011
-------------------------------
(missing bit)11 1110 = -2!!!
Any luck?
09-30-2015 01:09 AM
Are you trying to implement this with LabVIEW ? The fixed-point functions are your friends.
09-30-2015 01:09 AM - edited 09-30-2015 01:11 AM
09-30-2015 07:54 AM
You have the wrong value for b111101, which is -3: -2^5 + 2^4 + 2^3 + 2^2 + 1 = -32 + 29 = -3
And the 2's complement of that value is 000011, not 100011, so
01 1011 (27) + 00 0011 -(-3) ---------------
01 1110 (30)
You can use a 6-bit signed fixed-point control (WL=6 and IWL=6) with the radix visible to play with these values and see how it works.
09-30-2015 08:05 AM
@MissingBit wrote:
I'm trying to figure out this doozie: 01 1011 - 11 1101
use 2's complement to solve, 6bits signed.
As you should have learned at some point, another way of doing subtraction is to (2's)-complement the subtrahend and add.
Do you know how to do a 2's complement? Invert all the bits (1's complement) and add 1.
Two's complement of 11 1101 = 00 0010 + 00 0001 = 00 0011 (or decimal 3). Notice that this means that in 6-bit, your number is -3, not -29! This is probably the source of your frustration.
01 1011 - (11 1101) = 01 1011 + 00 0011 = 01 1100 = 30
27 - (-3) = 30
Doing the subtraction literally, starting from bit 0 -- 1 - 1 = 0 (bit 0), 1 - 0 = 1 (bit 1), 0 - 1 = 1 (bit 2, need to "borrow), 1 - 1 - 1(borrow) = 1 (bit 3, need to borrow), 1 - 1 - 1 = 1 (bit 4, need to borrow), 0 - 1 - 1 = 0 (bit 5), or 01 1100.
Bob ("Just like second grade, but missing 8 fingers") Schor
09-30-2015 10:27 AM
Ahem.
I'm sure that Bob meant to say the result in binary is 01 1110
Rod
(Checks typing......)
09-30-2015 12:12 PM
Oops ...
BS