Home Segments Index Top Previous Next

475: Mainline

You easily can forget which power of 2 corresponds to what position. Accordingly, it is a good idea to create an enumeration so that you do not have to remember the correspondence:

enum {bit0 = 1,  bit1 = 2,  bit2 = 4,  bit3 = 8 
      bit4 = 16, bit5 = 32, bit6 = 64, bit7 = 128}; 

Alternatively, once you have decided what each bit position is to represent, you can compose an enumeration to reflect your decisions:

enum {bad_size_bit = 1, bad_price_bit  = 2, 
      too_much_bit = 4, too_little_bit = 8};