取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 10 条)
7,862 次查看

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 项奖励
2 条消息(共 10 条)
7,857 次查看
0 项奖励
3 条消息(共 10 条)
7,853 次查看

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.眨眼表情


"Should be" isn't "Is" -Jay
0 项奖励
4 条消息(共 10 条)
7,848 次查看

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 项奖励
5 条消息(共 10 条)
7,840 次查看

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 项奖励
6 条消息(共 10 条)
7,832 次查看

Hello,

 

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

 

Thanks a lot.

 

0 项奖励
7 条消息(共 10 条)
7,824 次查看

Sorry, here's the VI

0 项奖励
8 条消息(共 10 条)
7,819 次查看

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 项奖励
9 条消息(共 10 条)
7,809 次查看
0 项奖励
10 条消息(共 10 条)
7,808 次查看