Bit Operations using Macros

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


// Define bitwise macros here
// #define SETBITS(X)  ((((X &= ~(1 << 3)) |= (1 <<2 )) |= (1 << 7)) ^= (1 << 5 ))     
#define ONE                     1
#define BIT_SET(val, pos)       val |=  (ONE << pos)
#define BIT_CLR(val, pos)       val &= ~(ONE << pos)
#define BIT_TOGGLE(val, pos)    val ^=  (ONE << pos)


uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    
   // SETBITS(reg);


    BIT_SET(reg, 2);
    BIT_SET(reg, 7);
    BIT_CLR(reg, 3);
    BIT_TOGGLE(reg, 5);
    
    return reg;
}


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

Input

0

Expected Output

164