I’m using Ignition to collect data from a GE Multilin 850 and some of the register values are stored in 2’s complement instead of signed int. I created an expression tag to convert the OPC tag value to signed int. Below is what I came up with for an 8 bit register, is there an easier way to convert 2’s complement?

// Example: -12.34 stored as -1234 i.e. 64302

// register 1 byte 1:

// register 1 byte 2:

//conversion of 2’s complement. 16th bit will identify if the number is negative or not.

if ((getBit({[.]Main_Pwr1_PF_2sComp},7)), //change position 15 to 7 when using 8 bit register

//if first bit is true, then flip all bits, subtract 1 and add a negative.

toInt((binEnc(

if (getBit({[.]Main_Pwr1_PF_2sComp},0),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},1),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},2),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},3),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},4),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},5),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},6),0,1), //invert the bit value

if (getBit({[.]Main_Pwr1_PF_2sComp},7),0,1) //invert the bit value

)-1)*(-1)), //subtract one and add a negative to the number

```
//if first bit is false, then convert to decimal number
toInt(binEnc(
getBit({[.]Main_Pwr1_PF_2sComp},0),
getBit({[.]Main_Pwr1_PF_2sComp},1),
getBit({[.]Main_Pwr1_PF_2sComp},2),
getBit({[.]Main_Pwr1_PF_2sComp},3),
getBit({[.]Main_Pwr1_PF_2sComp},4),
getBit({[.]Main_Pwr1_PF_2sComp},5),
getBit({[.]Main_Pwr1_PF_2sComp},6),
getBit({[.]Main_Pwr1_PF_2sComp},7)
)
)
)
```