uint8_t a = 0x01; //00000001 uint8_t b = 0xff; //11111111 uint8_t c = 0xf0; //11110000 maj(a,b,c) = 0xf1; //11110001
I'm not sure how to access and compare each bit so that I can arrive at a result?
result = (a & b) | (b & c) | (c & a);
@Henrik has already suggested a good straight forward solution that requires 5 operations. FWIW, if efficiency is an issue, you can reduce this to 4 operations:
result = (a & (b | c)) | (b & c);