Bit Operations using Macros

Code

#include <stdio.h>
#include <stdint.h>

// Define bitwise macros here
#define SET2 (1U << 2)
#define SET7 (1U << 7)
#define CLEAR3 ~(1U << 3)
#define TOGGLE5 (1U << 5)


uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    reg |= SET2;
    reg |= SET7;
    reg &= CLEAR3;
    reg ^= TOGGLE5;
    return reg;
}

int main() {
    uint8_t reg;
    scanf("%hhu", &reg);
    printf("%u", modify_register(reg));
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Expected Output

164