Search code examples
cuint8t

How to compare uint8_t array to a hex value in C?


I have predefined HEX values in my code. One of them is in the following.

#define ADDRESS1 0xD445556BD557
#define ADDRESS2 0xED612BDF113B

I also have an uint8_t array. Like

uint8_t MAC[6];

How can I compare this two things without writing a new function?

I have already tried

if(MAC == ADDRESS2)

Solution

  • Maybe you should use uint8_t array for ADDRESS* also, and use memcmp():

    static const uint8_t ADDRESS1[] = {0xD4, 0x45, 0x55, 0x6B, 0xD5, 0x57};
    
    if (memcmp(MAC, ADDRESS1, sizeof(ADDRESS1)) == 0)