bsc

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

luc108.c (904B)


      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 and exchange its higher 4 bits with lower 4 bits.
      9 */
     10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(f) */
     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, swapped;
     22 
     23     printf("Enter an 8-bit number (0-255): ");
     24     scanf("%hhu", &num);
     25 
     26     // Exchange nibbles
     27     // (num & 0xF0) >> 4 : High nibble to Low
     28     // (num & 0x0F) << 4 : Low nibble to High
     29 
     30     swapped = ((num & 0xF0) >> 4) | ((num & 0x0F) << 4);
     31 
     32     printf("Original: %d (Hex: 0x%02X)\n", num, num);
     33     printf("Swapped:  %d (Hex: 0x%02X)\n", swapped, swapped);
     34 
     35     return 0;
     36 }
© 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