Bit Operations using Macros

Code

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

// Define bitwise macros here
#define bit_op(x) do { \
    x = x | (1 << 2);        /* Set bit 2 */ \
    x = x | (1 << 7);        /* Set bit 7 */ \
    x = x & (255 ^ (1 << 3)); /* Clear bit 3 */ \
    x = x ^ (1 << 5);        /* Toggle bit 5 */ \
} while(0)

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    bit_op(reg);
    return reg;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

164