LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

01 1011 - 11 1101 = ? use 2's complement

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?

0 Kudos
Message 1 of 7
(4,169 Views)

Are you trying to implement this with LabVIEW ? The fixed-point functions are your friends.

0 Kudos
Message 2 of 7
(4,136 Views)

Hi Bit,

 

what's the problem?

check.png

And please explain how you want to represent "56" with a datatype only capable to hold values from "-32 to 31" (as you already stated)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(4,132 Views)

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.

 

0 Kudos
Message 4 of 7
(4,087 Views)

@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

 

 

0 Kudos
Message 5 of 7
(4,078 Views)

Ahem.

 

I'm sure that Bob meant to say the result in binary is 01 1110

 

Rod

(Checks typing......)

 

0 Kudos
Message 6 of 7
(4,049 Views)

Oops ...

 

BS

0 Kudos
Message 7 of 7
(4,017 Views)