Bit Operations using Macros

Code

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

// Define bitwise macros here
#define set_2_and_7(a) (a | 0b10000100)
#define clear_3(a) (a & ~(1<<3))
#define Toggle_5(a) (a ^ (1<<5))

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    reg=set_2_and_7(reg);
    reg=clear_3(reg);
    reg=Toggle_5(reg);
    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