Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Bytes and bits in Lookout

This is for a Lookout 5.0 application. The OPC Client Object reads a integer value (between 0 and 32767 plus a sign bit) that represents a 16 bit word. What I want is knowing the integer value, unpack the word into 16 bits. How can I do this in Lookout?"
0 Kudos
Message 1 of 3
(3,107 Views)
I needed to do this and found a quick, mathematical way. Here it is:

Lets say you have a 16 bit word with Bit#1 being the least significant bit- LSB- (farthest right) and Bit #16 being the most significant bit -MSB- (farthest left). As I am sure you know each bit has a decimal equivalent in value: Bit #1=1; Bit #2=2, Bit #3=4; Bit #4=8....Bit #15=16384, Bit#16=32768. The formual for a bit's value in decimal is (assuming the LSB satrts at 1 and not zero) 2^(Bit# - 1).
So to parse a 16 bit word here is the formula to use in an expression:

mod(int(Word/2^(Bit# - 1)),2) Ofcourse LSB bit# =1

Since the 16th bit is a sign bit you only need to look at the word's sign:

If(Word<0,1,0)

Regards,
Tommy Scharmann
Message 2 of 3
(3,107 Views)
Thanks. I'll try all this.
0 Kudos
Message 3 of 3
(3,107 Views)