Forum Discussion

JulianaMacedo's avatar
JulianaMacedo
Helper II
4 years ago
Solved

Add columns based on Bitwise operation

Hi!   I need to separate every bit in a byte and create a column for every bit that will state "Activated" or "the name of the bit" when a bit is activated. The solution that I'm doing now is pa...
  • AlB's avatar
    4 years ago

    Hi JulianaMacedo 

    It's not working because the 10000010 is being interpreted not as a binary number but as a decimal number by PQ. Try shifting 10000010 to the right and see the result. It won't be 1000001    

    You can store the 10000010 as text and then access the individual figures with

    Text.ToList([BinaryNumber]){0}  for the first figure (from the left)

    Text.ToList([BinaryNumber]){1}  for the second figure (from the left)

    etc

    then check whether that figure is a "1" (note you have to check for the character 1, not  number

    1, hence the "").

    So for bit 1 you would have

     

    (Byte0 as text) => if Text.ToList( Byte0 ){6} = "1" then "BIT 1" else ""

     

    for bit 3

     

    (Byte0 as text) => if Text.ToList( Byte0 ){4} = "1" then "BIT 3" else ""

     

    etc

    Note the number for accessing the different positions in the string is inverted vs what you were using

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.