I have an API response for door status, that returns in a sum of status.
e.g.
1 Open
2 Closed
4 Unlocked
8 Locked.
If the door is closed and locked it will return 9 and if its closed and unlocked it will return 5.
How would I break down the response in bubble? I have created a matching option set with the integer and strings, but not sure how to caculate to get the status without doing one for every combination.
A bitmask is hard to work with in Bubble, it lacks the “bit-wise AND” operator.
In javascript it is doable.
I assume you want to get a list of the enum flag numbers, here is Expression for on the page:
var flags = Input flags's value ;
var flaglist = [];
for(var i = 0; i < 15 && 2 ** i < flags; i++) {
if (2 ** i & flags) flaglist.push(2 ** i)
}
flaglist;
Note the constraint of 15, to keep the list small even for large input values. You can set yours to 11 if you want to stop at 1024.
Can run it on a backend workflow in server script with almost the same script.