Sign in to follow this  
Followers 0
JJH

Convert Decimal value into DINT bit value

4 posts in this topic

Hey all, I've reviewed a number of threads regarding converting one data type to another and I have something I'm working on that I'm stumped on and haven't found an answer for yet. Without getting into the details, I need to get a DINT bit value from an entered decimal value. A user will enter in a whole number in an entry box and then it needs to get converted to the number of whatever bits that the DINT number holds. For instance: # Entered Variable Bit Value -----0------------------0 -----1------------------1 -----2------------------3 -----3------------------7 -----4-----------------15 etc... I'm looking for a fairly clean way to do this, with perhaps just two or three instruction blocks to handle it, if possible. I can provide a screenshot of the HMI and the logic (4 rungs) if necessary. Any suggestions or advice from the group would be greatly appreciated!

Share this post


Link to post
Share on other sites
From your examples it looks like the PLC will set, in the DINT, that number of bits starting from the LSB. The end numeric value of the DINT would be (2 ** # Entered) -1 Though maybe I'm misinterpreting it.

Share this post


Link to post
Share on other sites
the bit values mentioned in example don't make sense. weights of bits (from LSB) are 1,2,4,8,16,... another thing is "decimal" format. decimal numbers are all numbers with base10 and they can be integers or floating point values. if the issue is that operator types in decimal point and few more digits, that is not jis fault, just change or restrict HMI entry to accept integers only. again, my interpretation of what is wanted may be off...

Share this post


Link to post
Share on other sites
The CPT instruction worked but I had to offset it by a -1 because of how AB handles their variables (2**Variable-1). Thanks for the suggestion!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0