Decimal to Binary Conversion

kpguy

Member
Join Date
May 2008
Location
Here
Posts
13
In any Logix5000 processor and any version from 15 through 17, I am looking for a way to convert a decimal number of 1 through 8 to a binary that will represent a mask. This lets me tell a loop in the plc which analog inputs to ignore the faults from if I tell the subroutine how many I am using. So if I am using one then the mask should be 2#00000001, if two then 2#00000011, three will be 2#00000111 up to eight of 2#11111111. I dont want to just do a crude lookup table, I would like it to be buried in the code so that no tags can be changed.

Im trying to figure if there is a simple equation I can write or not.

Thanks

edit: It needs to work in ladder logic, not text or anything else
 
Last edited:
There is nothing crude about what you would call a lookup table.

I'm not well versed in rsl5k but there should be a way to access a single bit from a word tag. I'm guessing using a dot operator would do it.



MaskOut1 MaskWord.0
---] [--------------------------------( )------

MaskOut2 MaskWord.1
---] [--------------------------------( )------


etc...



Clean, simple, understandable...
 
I would like it to be buried in the code so that no tags can be changed.

Missed this comment the first time. If your intent is to purposely obfuscate the intent of the code you could do a series of bit shift left instructions based on the number of masked out signals, then use AND instructions to keep ANDing them together. You could also XOR the mask with the same value twice in different parts of the program to get back the original mask.


👨🏻‍🏫 I don't recommend this method. I would rather keep the code simple and put security on the ladder file than make a mess like this.
 
To clairify, if your number is N you want a mask represented by ((2^N)-1).

Try using the XPY command. Source A = 2, Source B = N (from above), Dest = tag. Then take tag - 1.

Make an AOI out of it to hide the method. Just in and out.
 
To clairify, if your number is N you want a mask represented by ((2^N)-1).

Try using the XPY command. Source A = 2, Source B = N (from above), Dest = tag. Then take tag - 1.

Make an AOI out of it to hide the method. Just in and out.
Thats the math I was looking for. And as far as hide it, maybe hide was the wrong term. I just wanted it to be all in one CPT instruction, not a lookup table that I would have to define tags or an array that somebody could change the values easier than by editing rungs. And AOI's don't exist in V15.

Thanks
 

Similar Topics

Hi I'm using a Mitsubishi PLC (FX Series) and want to convert 4 inputs from binary format to decimal. I can do this via ladder logic using...
Replies
4
Views
6,677
Hey, I'm looking for a bit of guidance on some vba code in RSView32. For the record I know zero (I know its shameful) VBA code. What I'm trying...
Replies
7
Views
5,592
I am trying to mask the first 8 digits of binary code in a Allen Bradley remote I/O module for alarm tracking puposes. I only need to read the...
Replies
3
Views
3,231
Hello, I am currently using the PanelView Plus 1000 to poll a modbus device use Kepware drivers. The problem I have is I am polling a holding...
Replies
5
Views
4,119
Good morning, I have recently upgraded a program from PLC2 up to RS5000. I have a need to convert a decimal number to binary.(non-bcd)The way...
Replies
3
Views
5,934
Back
Top Bottom