luc106.c (965B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program to scan an 8-bit number and check whether its 3rd, 6th and 7th bit is on. 9 */ 10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(d) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <stdlib.h> 18 19 int main() 20 { 21 unsigned char num; 22 23 printf("Enter an 8-bit integer (0-255): "); 24 scanf("%hhu", &num); 25 26 // Checking bits 3, 6, 7. 27 // Assuming 0-based indexing: 3rd bit is index 3 (value 8), 6th is index 6 (64), 7th is index 7 (128). 28 29 unsigned char mask = (1 << 3) | (1 << 6) | (1 << 7); 30 31 if ((num & mask) == mask) 32 printf("Bits 3, 6, and 7 are ALL ON.\n"); 33 else 34 printf("Bits 3, 6, and 7 are NOT all on.\n"); 35 36 return 0; 37 }