Decimal to Binary, again

jims

Senior Member
I have a project using a 20m2, with PE6 version 6.0.8.11. There are 5 digital sensors attached to DI. The statement (Let b1=pinsC nor %11100000) returns a decimal value from 0 to 31. With "debug" the Code Explorer shows a binary value for b1. I want to be able to convert the decimal value to binary and display it with a SERTXD statement. Have searched the FORUM with the argument "Convert decimal to Binary". There has been much activity about this but I'm not smart enough to understand if I can/can't do it. Is there a routine that will take my decimal value (0 to 31) and convert it to binary (eg: 9=01001)?
Thank you, JimS
 

hippy

Technical Support
Staff member
The easiest way to output binary with SERTXD is to move the variable to b0 or w0 then output the bit variables which make up that variable ...

Code:
b0 = 130
SerTxd( #b0, " = %", #bit7, #bit6, #bit5, #bit4, #bit3, #bit2, #bit1, #bit0, CR, LF )
For your 5-bit, 0-31, example ...

Code:
b0 = 9
SerTxd( #b0, " = %", #bit4, #bit3, #bit2, #bit1, #bit0, CR, LF )
 

jims

Senior Member
Thank you...hippy. This works "like a charm". Also, my ageing memory often lags and I usually forget that I must use b0 when "picking bits". JimS
 
Top