# LabVIEW

cancel
Showing results 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?

Message 1 of 7
(3,598 Views)

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

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

Message 2 of 7
(3,565 Views)

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

Hi Bit,

what's the problem?

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
Message 3 of 7
(3,561 Views)

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

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.

Message 4 of 7
(3,516 Views)

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

@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

Message 5 of 7
(3,507 Views)

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

Ahem.

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

Rod

(Checks typing......)

Message 6 of 7
(3,478 Views)

Oops ...

BS

Message 7 of 7
(3,446 Views)