LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

conversion of twos complement

We want to communicate a temperature controller with Lab view for visualization the temperature and in order to control the temperature via lab view.

In the attached sheet we are implementing the logic / procedure required for of controller communication.
1- Header value is (colon) : ( 2 byte)
2- Salve address is variable, it is a device number (2 byte) e.g. 01
3- Data item is variable (2 byte) e.g. 03
4- Function is any function to performed e.g. set temp 0003, set alarming 0004
(4 byte)
5- Data is the actual value to be communicate e.g. 1234 (4byte)
6- LRC check byte (4 bytes), which is a 2�s complement of item 2, 3, 4 and 5.

Hence the total TX value is of 18 byte (: 01 03 0003 1234 and LRC 4 byte )


In order to generate a check byte (4 bytes) LRC we add the above items value, item # 2+ 3+ 4+5 and finally convert it into 2�s complement. I.e.

1- Covert all item value string to number
2- Then add item # 2, 3, 4 and 5 value
3- Convert this number to integer (Double word).
4- Convert the number to Boolean array
5- Invert the number for 1�s complement
6- Convert the Boolean array to number
7- Add +1 for 2�s complement
8- Finally we get the 4 byte LRC

The above LRC working properly if data is 1 byte i.e. 8 bit, however when we have 4-byte i.e. double word it will show some error. Therefore I need help i.e. how to covert the double word to 2�s complement. Is there any solution to directly convert 4 byte (double word) to 2�s complement?

Advance thanks to all professional

ASAD
0 Kudos
Message 1 of 6
(5,313 Views)

Try inserting another "to Word interger" before you feed the +1 node. The output of the number to boolean is I32 so you are not working with a I16 like you expect.

If you go to the wiring tool and do a ctrl-h (help window) it will tell you the datat type of the wire you are looking at.


Ben


Ben Rayner
Certified LabVIEW Developer
www.DSAutomation.com

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 6
(5,313 Views)
Dear Ben

The problem is not solved by your nice suggestion .plz let have a look on the exact problem I am facing:

In the new attached diagram if we send the integer value up to 8 bit or 16 bit the 1�s and 2�s complement function perfectly, However when we have data in b/w e.g. 11 bit then the answer will be wrong e.g.

Suppose we have an integer value 1251

Binary conversion is : 10011100011
1�S complement should be 01100011100 (796) however in case of I16 it will be
11111 01100011100 which is wrong.
Also 2�s complement should be 01100011101 (797) however in case of I16 it will be
11111 01100011101 wrong.

Actually we need to use I32 i.e. double word. In this situation the problem create more errors.
Plz help me to solve out
the problem in case of variable data. (E.g. 30 bits, 20 bits or any other data, not the case of fixed 32 bit data).
0 Kudos
Message 3 of 6
(5,313 Views)
See attached.

The issue you are running into is LV uses "Zero Extend" represenations of numbers. That means leading zero's matter.

What you have described so far sounds like you wnat "no-Zeor Extend" 1 and 2's complement. This is not native to LV.

The attached VI deminstartes the issue along with some methods to deal with it. Some good some not so good. You decide.

It demonstrates using logic operators on numerics to get 1 and 2's complement.

It also shows how to use string indicator to show lead zeros of binary numbers.

It also demonstrates a method for doing variable lenth non zero extended complemnting.

Sorry I was not able to look at your posting.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 6
(5,313 Views)
Mr Ben
can you advice me the version that you are using to create the structral logic , as I am unable to open it in version 5.1
regards
asra
0 Kudos
Message 5 of 6
(5,313 Views)
Here is a bmp of my LV 6.1 version.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 6
(5,313 Views)