dimanche 27 juin 2021

How `(1U << 1) | (1U << 5)` is different from `0x22`?

Would someone please explain me how having the same value VAL1 and VAL2 behave differently? For the first if statement VAL1 is equal to zero? Thanks!

#include <stdio.h>

#define VAL1 (1U << 1) | (1U << 5)
#define VAL2 0x22

int main()
{
    printf("VAL1: %d\r\n", VAL1);
    printf("VAL2: %d\r\n", VAL2);

    if (VAL1 == 0)
    {
        printf("TRUE 1\r\n");
    }

    if (VAL2 == 0)
    {
        printf("TRUE 2\r\n");
    }

    if (VAL1 == VAL2)
    {
        printf("TRUE 3\r\n");
    }
}

Output:

VAL1: 34
VAL2: 34
TRUE 1
TRUE 3

Aucun commentaire:

Enregistrer un commentaire