Announcement

Collapse
No announcement yet.

Convert word to bit index

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts


  • Convert word to bit index

    Hello,

    I have a screen on an HMI (C-more) that has a radio button. On the C-more, the radio button allows the set value to be stored in a WORD tag.

    So as the user selects the radio button, the WORD changes from 1,2,4,8, etc..

    That's fine so far. What I'm wondering is if there is a way to convent that into incremental numbers that represent the index of the bit that is active within the WORD.

    So,

    1,2,4,8,16,32 becomes 1,2,3,4,5,6,7 etc.

    I don't see an easy way to do this without creating a separate tag for each option.

    Thanks
    FF


  • #2
    you could use a For Loop and a bitshift right and compare the shifted value to get the bit position of the HI bit.
    Last edited by kewakl; 05-17-2019, 12:48 PM.

    Comment



    • #3
      Click image for larger version

Name:	bitposition.png
Views:	0
Size:	115.6 KB
ID:	122804

      Comment



      • #4
        Lookup Table can be used for this. Just use it as a single row instead of a matrix.
        Attached Files

        Comment



        • #5
          ^ I like and more characters to satisfy the forum overlords - have to have more characters per post, but must wait 1 minute between posts

          Comment

          Working...
          X