All submissions

Bit Operations using Macros

Code

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

// Define bitwise macros here
#define SET_BIT(REG,POS)       (REG |= (1U<<POS))
#define SET_BIT_MASK(REG,MASK)  (REG |= MASK)
#define CLEAR_BIT(REG,POS)     (REG &= (~(1U<<POS)))
#define TOGGLE_BIT(REG,POS)   (REG ^= (1U<<POS))

#define SET_POS     ((1<<2)|(1<<7))
#define CLR_POS     3
#define TOGGLE_POS  5


uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    SET_BIT_MASK(reg,SET_POS);
    CLEAR_BIT(reg,CLR_POS);
    TOGGLE_BIT(reg,TOGGLE_POS);
    return reg;
}

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

Solving Approach

 

 

 

Loading...

Input

0

Expected Output

164