In: Computer Science
write a c code to test the 3rd and 8th bit set or not
(1 or 0).
if both set, display "true";
if either one set, display "half true";
if neither set, display "false".
//Always remember bit order starts from 0.
#include <stdio.h>
int main()
{
int num, n, bitStatus,bitStatus1; //integer
declaration
/* Input number from user */
printf("Enter any number: ");
scanf("%d", &num);
/* Right shift num,3 times and perform
bitwise AND with 1 */
bitStatus = (num >> 3) & 1;
/* Right shift num,8 times and
perform bitwise AND with 1 */
bitStatus1 = (num >> 8) &
1;
if(bitStatus==1 && bitStatus1==1){
printf("true");
}
else if(bitStatus==1 || bitStatus1==1){
printf("half true");
}
else{printf("false");
}
return 0;
}