LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2's complement

Hello,

 

I was trying to get the 2's complement of a binary number and convert that number to a decimal. But I couldn't get the right 2's complement.

 

For example, the 2's complement of 10111  is 01001.

 

How can I achieve that in Labview?

 

Thanks a lot.

 

 

0 Kudos
Message 1 of 10
(7,209 Views)

http://digital.ni.com/public.nsf/allkb/57EC3CCB9DA0756786256649006421FF

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 10
(7,204 Views)
0 Kudos
Message 3 of 10
(7,200 Views)

not that its difficult......

!0.png

But knowing what it is and how its defined helps.  Of course, its necessary to understand that an integer's value does not change when you change the radix it is displayed in.Smiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 10
(7,195 Views)

Hi Jim,

 

I tried that but I could not get the right number.

 

Like I passed 10111 through the NOT function and it gives me -10112. Then I added 1 and it gives me -10111.

 

Thanks

0 Kudos
Message 5 of 10
(7,187 Views)

ZCY4444 wrote: 

Like I passed 10111 through the NOT function and it gives me -10112. Then I added 1 and it gives me -10111.


What is the exact data type and display formatting of your 10111 number? Please attach a small VI containing your input. Thanks.

0 Kudos
Message 6 of 10
(7,179 Views)

Hello,

 

I have attached the vi. Please review it and point out my mistake.

 

Thanks a lot.

 

0 Kudos
Message 7 of 10
(7,171 Views)

Sorry, here's the VI

0 Kudos
Message 8 of 10
(7,166 Views)

I think your code is fine if you get rid of all the string conversions. Instead, use the Radix display (right-click on a numeric control, Visible Items -> Radix). This lets you switch the display of a number from decimal to base 2 (and to hex or octal as well).

 

If you must do string conversions (again, not needed), use the correct format specifier. %f is for a floating-point value. For an integer, use %d (signed) or %u (unsigned).

0 Kudos
Message 9 of 10
(7,156 Views)
0 Kudos
Message 10 of 10
(7,155 Views)