Logically ANDing two hex valuse

Hi, I'm struggling to see what I'm doing wrong, I have a hex value returned from an array, say 0xc0 and I want to && it with 0x7F before I send it to a function and the serial port.


The SEGMENT_MAP[Value] returns 0xC0, this should, when && with 0x7F send out 0x40 but it sends 0x01, what am I doing wrong?

&& is for comparison. From the reference:

&& (logical and True only if both operands are true, e.g. if (digitalRead(2) == HIGH && digitalRead(3) == HIGH) { // read two switches // ... } is true only if both inputs are high.

For a mask you want bitwise and (&).

DOH! :blush: See I knew I was doing something stupid. Too many languages, to few brain cells. Thanks