I'm trying to understand this cpp code so I can convert it to Java. r1 is an unsigned int bit field but it looks like here it is being set to a boolean value?
union GpioPins {
    struct {
      unsigned int ignoredPins1:2;
      unsigned int r1:1;
      unsigned int g1:1;
      unsigned int b1:1;
    } bits;
    uint32_t raw;
    GpioPins() : raw(0) {}
  };
then later on a loop containing
 GpioPins *bits = ...
 uint8_t red   = 141; // any number between 0..255
 uint8_t mask = 1 << i; // i is between 0..7 
 bits->bits.r1 = (red & mask) == mask;
The line that is confusing is the final one. Doesn't (red & mask) == mask resolve to true or false?
i.e. in Java this should look like:
 private static class GpioPins {
    static class Pins {
        int ignoredPins1;
        int r1;
        int g1;
        int b1; 
    }
    int raw = 0;
    Pins bits;
}
then later
GpioPins bits = ...
int red   = 141; // any number between 0..255
int mask = 1 << i; // i is between 0..7 
bits.bits.r1 = (red & mask) == mask;  // compile error, incompatible types
There is clearly something I don't understand in the cpp code, but don't know what it is to google it :-)
 
     
    