Bit Operations using Macros

Code

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

// Define bitwise macros here
#define SETS_B2B7(x)   x = x | (1 << 7) | (1 << 2) 
#define CLEAR_B3(x) x &= ~(1 << 3)
#define TOGGLE_B5(x) x ^= (1 << 5) 

uint8_t modify_register(uint8_t reg) {
    SETS_B2B7(reg);
    CLEAR_B3(reg);
    TOGGLE_B5(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