11-15-2013 11:34 AM
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.
11-15-2013 11:37 AM
11-15-2013 11:44 AM
See if any of these threads help:
http://forums.ni.com/t5/LabVIEW/2-s-complement/td-p/280843
http://forums.ni.com/t5/LabVIEW/2-s-complement-of-double/td-p/1892609
http://forums.ni.com/t5/LabVIEW/14-bit-twos-complement/td-p/1246942
11-15-2013 11:48 AM
not that its difficult......
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.
11-15-2013 12:00 PM
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
11-15-2013 12:10 PM
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.
11-15-2013 12:22 PM
Hello,
I have attached the vi. Please review it and point out my mistake.
Thanks a lot.
11-15-2013 12:26 PM
Sorry, here's the VI
11-15-2013 12:50 PM
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).
11-15-2013 12:51 PM
Try this function. 😄