bsc

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

root / semester_1 / letusc / luc110.c

luc110.c (848B)


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