Looking for a way to perform Bitwise OR operation between n number.

Hi there,

 We  have a requirement where we need to generate masked value, based on the selected checkbox,

For generating masked value, we will be required to perform bitwise or operation between the selected value of the checkbox.

let us say we have 4 checkbox 

SUNDAY = 0 

 Monday = 1

Tuesday = 2

Thursday =3

 now based on the user selection we need to perform the bitwise or operation  between the selected value i.e

masked value  |=  (0,1,3)

is there any way to perform the bitwise or operation in Appian..?

 

Thanks in advance.

  Discussion posts and replies are publicly visible

Parents
  • Hi Malay,

    dec2bin would help you. With this function, you can transform a base-10 integer to a binary, represented as string. You can then iterate over the elements of the string and perform a bitwise operation of your choice. If you take an array containing n elements and iterate through it with the mid() function, you get a list of all relevant bit values, which you can then compare using or().

    Kind of like the below sample, which I encourage you to use and test to see whether it fulfills for requirement. Let me know.

    a!localVariables(
      local!places: len(dec2bin(max(ri!array))),
      local!binArray: dec2bin(ri!array,local!places),
      concat(
        a!forEach(
          items: enumerate(local!places)+1,
          expression: tointeger(or(mid(local!binArray,fv!item,1)))
        )
      )
    )

Reply
  • Hi Malay,

    dec2bin would help you. With this function, you can transform a base-10 integer to a binary, represented as string. You can then iterate over the elements of the string and perform a bitwise operation of your choice. If you take an array containing n elements and iterate through it with the mid() function, you get a list of all relevant bit values, which you can then compare using or().

    Kind of like the below sample, which I encourage you to use and test to see whether it fulfills for requirement. Let me know.

    a!localVariables(
      local!places: len(dec2bin(max(ri!array))),
      local!binArray: dec2bin(ri!array,local!places),
      concat(
        a!forEach(
          items: enumerate(local!places)+1,
          expression: tointeger(or(mid(local!binArray,fv!item,1)))
        )
      )
    )

Children