# Integer to binary conversion

## Recommended Posts

Hi!

How is it possible to convert a data from PLC to convert it to Binary data.

Best regards,

Wuchi

##### Share on other sites

Hi!

How is it possible to convert a data from PLC to convert it to Binary data.

Best regards,

Wuchi

Maybe i haven't asked from the right angle

I have for example integer of value 400, how can i convert it to binary data in DAQ?

Wuchi

##### Share on other sites

I am not sure what you mean. Do you want to display the integer on the screen as a string of 1s and 0s?

##### Share on other sites

Yes i want to convert integer to binary data

For example i get an integer of 2 and this represents 10 in binary.

W.

##### Share on other sites

There actually is no simple way to do this, even in Release 5.3 which allows easy conversion from dec to hex and dec to octal.

That said, you can use the TestBit() function to examing each bit your number, which is usually what you want to do. For example, TestBit(503,2) returns 1.

If you actually want to do a conversion, you could write a simple sequence function:

Private.strOut = ""

for (Private.x = 7, Private.x >= 0, Private.x--)

Private.strOut += Format("%.0f",TestBit(Private.arg0,Private.x))

endfor

return(Private.strOut)

This will convert a decimal number into an 8 bit binary number. Change the 7 to 15 and you can do 16 bit binary.