All submissions

Bit Operations using Macros

Code

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

// Define bitwise macros here
#define set(n)  (((n | (1<<2))  \       // seting the bit at 2nd position
                    | (1<<7) )  \       // seting the bit at 7th position 
                    ^ (1<<5) )  \       // toggleing the 5th bit
                    & ~(1<<3)           // clear the bit at 3rd position

uint8_t modify_register(uint8_t reg) {
    // Apply operations in order
    return set(reg);
}

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

Solving Approach

// Define bitwise macros here

#define set(n)  (((n | (1<<2))  \       // seting the bit at 2nd position

                    | (1<<7) )  \       // seting the bit at 7th position 

                    ^ (1<<5) )  \       // toggleing the 5th bit

                    & ~(1<<3)           // clear the bit at 3rd position


 

uint8_t modify_register(uint8_t reg) {

    // Apply operations in order

    return set(reg);

}

 

 

Loading...

Input

0

Expected Output

164