Iterating through a list and an integer

I have a list of buttons.
I want to set whether or not they're enabled based on bits in a corresponding binary integer.

So I want to do something like the code below, but I can't find blocks with which to do it in AI2.
Any suggestions?

for (int i=0; i<10, i++)
{
  if (bitRead(A , i) == 1)
    {
      button_list.enable[i] = true;
    }
  else
  {
    button_list.enable[i] = false;
  }
}

:question:

A = 1110001010
Bit 0 of A = 0 so button#0 is disabled
Bit 3 of A = 1 so button#3 is enabled

Probably this:

[EDIT - the for each item in list is the incorrect block to use, see a few posts down for the correct blocks]

Depending on your Android version, you may need this:

image

earlier versions of android add an empty list item at index 1 when splitting characters with an empty string

The IDE won't accept the two instances of "binary" as and argument when it needs a list ... and I can see why. :slight_smile:

And I can't get my head round the concept of "thing". (Even after repeatedly reading the documentation.)

Explain what you mean - IDE ?

Show your blocks

Sorry, my error, you need to use the for each number from block

1 Like

Got it. Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.