Hello, I'm a newbie in c programming. Can someone help me on this assignment. The code is what I have done so far: part_2.c
PART2: Bit Masking (3 marks)
- Initialize an 8-bit binary number (call it num1) that equals the last digit of your student#.
- Initialize a binary mask (call it mask1) that equals the next digit (before the last) of your student#.
- Your code should implement the following:
- OR mask1 with num1, print the result
- toggle num1, print the result
To check part (a): use num1=0b00000101 and mask1= 0b00000010. The result is 7
To check part (b): for the same num1, result is -6
- In the space below, attach a screenshot of the code and the results window.
Code:
#include<stdio.h>
void bit_mask(unsigned char x) {
unsigned char m = 0x80;
for ( ; m; m >>= 1){
putchar(x & m ? '1' : '0');
}
putchar('\n');
}
int part_2() {
char a[] = "4";
unsigned char b[4];
size_t i;
for (i = 0; i < 2; i++){
b[i] = a[i] - '0';
}
for (i = 0; i < 2; i++){
bit_mask(b[i]);
}
return 0;
}