bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc110.c (1039B)


      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 /* Receive an 8-bit number. Check if 3rd and 5th bits are ON. If yes, put them OFF.
      9 */
     10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(h) */
     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     unsigned char mask = (1 << 3) | (1 << 5); // Bits 3 and 5
     23 
     24     printf("Enter an 8-bit number: ");
     25     scanf("%hhu", &num);
     26 
     27     if ((num & mask) == mask)
     28     {
     29         printf("Bits 3 and 5 are ON. Turning them OFF...\n");
     30         // XOR with mask toggles 1 to 0 (since they are 1)
     31         // OR: AND with complement mask (~mask)
     32         num = num & ~mask;
     33     }
     34     else
     35     {
     36         printf("Bits 3 and 5 are NOT both ON. No change.\n");
     37     }
     38 
     39     printf("Final Value: %d (0x%02X)\n", num, num);
     40 
     41     return 0;
     42 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror