If statement not working

Hey I’m just tinkering with a RC522 RFID module and I’m just trying to do a very basic verification system where it checks the UID of the fob against a UID hardcoded in to the program. However, the if statement is executing even when it’s false. I’ll explain more but here is the code:

byte masteruid[] = {0xA4, 0x57, 0x51, 0x2E};
        int truth = 0;
        for (byte i = 0; i < mfrc522.uid.size; i++) {
                //To check the output of the statement
                Serial.print((mfrc522.uid.uidByte[i], HEX) == (masteruid[i], HEX));
                
                if ((mfrc522.uid.uidByte[i], HEX) == (masteruid[i], HEX)) {
                  truth++;
                }
                if (truth == 4) {
                  Serial.println();
                  Serial.print("It worked.");
                }
        }

The line “Serial.print((mfrc522.uid.uidByte, HEX) == (masteruid_, HEX));” I added for debugging purposes to check whether it was evaluating as true or false. The output of this was always “1111”, so true for each byte, regardless of whether it actually was the right value, and even if I put something random instead, like “(mfrc522.uid.uidByte*, HEX) == 7)”, although it would evaluate as 0000, so false every time, it would still execute truth++ and hence print “It worked.”*
I’m a very inexperienced programmer and only really have an okay knowledge of Python. Can somebody help please!?_

What do you think this is going to do?

Serial.print((mfrc522.uid.uidByte_, HEX) == (masteruid*, HEX));_ _.*_

LarryD: What do you think this is going to do?

Serial.print((mfrc522.uid.uidByte_, HEX) == (masteruid*, HEX));_ _._ _[/quote]_ _*I thought it would print to the Serial Monitor whether the statement evaluated as 1 or 0, depending on whether the first byte of the UID matched the first byte of the master UID? Is this wrong?_

if ((mfrc522.uid.uidByte[i], HEX) == (masteruid[i], HEX))

Here the comma operator throws away what's in front of it and evaluates what's behind it. So this becomes:

if (( HEX) == ( HEX))

where HEX is defined as 16. So you can see it will always be true.

Get rid of the comma and HEX, they are not needed. If the numbers are equal in HEX format they'll be equal in any format.

if (mfrc522.uid.uidByte[i] == masteruid[i])

Thanks very much Delta_G that fixed it!