Control Builder - How to extract LSB & MSB from INT
Or I want to read LSB & MSB of a INTEGER to 2 separate signal ?
Voted best answer
There's no need for complicated conversions or fancy user code ...
Use the "TestBIT()" function to test any bit position in an integer You can also use the related "SetBit()" and "ClearBit()" functions to manipulate individual bits
Or you can just Bitwise AND with 16#1 for the LSB. Similarly you can Bitwise AND with 16#0F to get the lower 8 bits and 16#F0 to get the upper 8 bits.
The MSB of any Signed integer is always the "Sign" so if the value of an intger is negative the MSB is by definition "1" (explanation ... https://en.wikipedia.org/wiki/Two%27s...)
Answers
Convert your integer (say dint type) to identical bit string (dword) using system function dint_to_dword function.
This would convert your integer to haxa decimal notation. You can use dint_to_word as well.
For more details, use online help.
Hi,
You should first convert the INT to dword.
Next and the converted dword with 16#00FF to get the MSB, then use SHR to shift bits by 8 and then and it again with 16#00FF to get the MSB. You can convert the LSB and MSB back to integer format if needed.
Hello,
In 800m CBM has the feature like int_dint and dint to bc then you will get 16 bit data then you manipulate as you need it
Add new comment