Bit Operations using Macros

Code

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

// Define bitwise macros here
#define SET(reg, pos)     ((reg)|(1<<pos))
#define CLEAR(reg, pos)     (reg&(~(1<<pos)))
#define TOGGLE(reg, pos)    (reg^(1<<pos))

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    
    uint8_t num = reg;
     num =  SET(num,2) ; 
     num =  SET(num,7) ;
     num =  CLEAR(num,3) ;
     num =  TOGGLE(num,5) ;
    
    
    
    return num;
}

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