Decimal To Binary ????

Carl 7 years ago in IQANdesign updated by Ulrik Zakariasson (Software development) 7 years ago 2

Hi Guys,

Has anyone found a way to convert a decimal to binary?

We are trying to do it so we can take an SPN say SPN 2923 and convert it to binary (101101101011)

We then take this and chop it up to last 3 (011) and copy to a Byte 5 (Bit 6-8) then the next 8 (01101) Byte 4 (Bits 1 - 8) then the last 4 (1101) add 0 to fill (00001101) and copy this to Byte 4. This allows an SPN to be inputted and converted to DM1 to send.


Hello Carl.

You could break out the different values you want by making a bit mask with the help of 'band' (Bitwise and) functions in a math channel.

For example the last 3 bits, do a biwise and between the SPN number and 0x7, then you would mask out all except the 3 least significant bits.

For the next 5 bits you do a bitwise and between the SPN and 0xF8, then use the 'shr' (shift right) function and move the value 3 steps. then you have the value for those 5 bits.

If you really need each bit you could use a internal digital channel (one per bit) and do a bit mask for each bit in the SPN.