All submissions

Bit Operations using Macros

Code

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

#define SET_BIT(REG, POS) ((REG)  |= (1 << (POS)))
#define CLEAR_BIT(REG, POS) ((REG)  &= ~(1 << (POS)))
#define TOGGLE_BIT(REG, POS) ((REG)  ^= (1 << (POS)))

inline void set_bit(uint8_t* reg, uint8_t pos)
{   
    *reg |= (1 << pos);
}

inline void clear_bit(uint8_t* reg, uint8_t pos)
{
    *reg &= ~(1 << pos);
}

inline void toggle_bit(uint8_t* reg, uint8_t pos)
{
    *reg ^= (1 << pos);
}

// Define bitwise macros here

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

    set_bit(&reg, 2);
    set_bit(&reg, 7);
    clear_bit(&reg, 3);
    toggle_bit(&reg, 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