4. Set the Bit in an 8-bit Register

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <stdint.h>
unsigned char setBit(unsigned char reg, int pos){
    reg |=(1 << pos);
    return reg;
}
int main() {
    unsigned char reg;
    int pos;
    scanf("%hhu %d", &reg, &pos);
    printf("%d\n", setBit(reg, pos));
    return 0;
}

Solving Approach
 

 

 

Was this helpful?
Upvote
Downvote