bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_1 / letusc / luc106.c

luc106.c (774B)


      1 /* Write a program to scan an 8-bit number and check whether its 3rd, 6th and 7th bit is on.
      2 */
      3 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(d) */
      4 
      5 /* This file is auto-generated by a bot. */
      6 /* This code is not compiled; it is for reference only. */
      7 
      8 
      9 #include <stdio.h>
     10 #include <stdlib.h>
     11 
     12 int main()
     13 {
     14     unsigned char num;
     15 
     16     printf("Enter an 8-bit integer (0-255): ");
     17     scanf("%hhu", &num);
     18 
     19     // Checking bits 3, 6, 7. 
     20     // Assuming 0-based indexing: 3rd bit is index 3 (value 8), 6th is index 6 (64), 7th is index 7 (128).
     21     
     22     unsigned char mask = (1 << 3) | (1 << 6) | (1 << 7);
     23 
     24     if ((num & mask) == mask)
     25         printf("Bits 3, 6, and 7 are ALL ON.\n");
     26     else
     27         printf("Bits 3, 6, and 7 are NOT all on.\n");
     28 
     29     return 0;
     30 }