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.
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
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.![]()
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
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.
Sorry, here's the VI
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).