Bit Operations using Macros

Code

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

// Define bitwise macros here
#define SETBIT(reg, pin)    (reg |= (1<< pin))
#define CLRBIT(reg, pin)    (reg &=~ (1<< pin))
#define TOGBIT(reg, pin)    (reg ^= (1<< pin))
uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    SETBIT (reg,2);
    SETBIT (reg,7);
    CLRBIT (reg,3);
    TOGBIT (reg,5);
    return reg;
}

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

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Expected Output

164