All submissions

Bit Operations using Macros

Code

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


#define SET_BIT(REG, BIT)     ((REG) |= (BIT))
#define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
#define TOGGLE_BIT(REG, BIT)  ((REG) ^= (BIT))

// Define bitwise macros here
#define BIT_2 (1U << 2)
#define BIT_3 (1U << 3)
#define BIT_5 (1U << 5)
#define BIT_7 (1U << 7)

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    SET_BIT(reg, BIT_2);
    SET_BIT(reg, BIT_7);
    CLEAR_BIT(reg, BIT_3);
    TOGGLE_BIT(reg, BIT_5);
    
    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