LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bit Operations

I'm attempting to do some bit operations on a decimal value that I need to output as binary to my instrument. Using universal libraries Digital out vi, I can send an integer value out as a binary number. Is it possible to perform bit operations on a decimal value using the formula node and logical operators? I need to make the LSB, the MSB. For example, a decimal value of 128 in binary is 10000000. I would need to output this as 00000001. I was trying to use a formula node like this: y = (x && 1) ? 128:0 ..... y = (x && 128) ? 1:0 for all the eight bit values. Then I would add all the values up and send that to DOUT. So in my example beginning with a decimal value of 128 and sending it to eight formula nodes I would like to get false values unti
l y = (x && 128) ? 1:0. Then the compound addition would yield one and this value would be sent out to my instrument as binary 00000001. Unfortunately, I get true values out of all my formula nodes. How can I accomplish the bit operations I need to perform on a decimal value and then send it as an integer value to DOUT? The example is simplified, the actual decimal values are large. Any help would be greatly appreciated.
0 Kudos
Message 1 of 4
(3,115 Views)
To get 128 in binary (10000000) to 00000001 you can use the rotate function located in function palette under advanced->data manipulation.
0 Kudos
Message 2 of 4
(3,115 Views)
If you want to use a formula node, review the C syntax for && (logical AND) and & (bit-wise AND);
For example,
int x,y,z;
x=2;
y=x&&1; // logical AND: y=1
z=x&1; // bit-wise AND: z=0

The LabView AND function (from the Boolean palette, not in a formula node) works like the bit-wise AND.
0 Kudos
Message 3 of 4
(3,115 Views)
I don't know about the formula node but you could just use a few labview functions. Change it into an array of bits using number to boolean array and boolean to (0,1). Use reverse array and then change it back to a number using 'not equal to zero?' and boolean array to number. Not sure if that is better or simpler than using a formula node but it is another option.
Message 4 of 4
(3,115 Views)