bsc

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

luc107.c (986B)


      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 unsigned 16-bit integer and exchange the contents of its 2 bytes using bitwise operators.
      9 */
     10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: B(e) */
     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 short num, swapped;
     22 
     23     printf("Enter a 16-bit number (0-65535): ");
     24     scanf("%hu", &num);
     25 
     26     // Exchange bytes:
     27     // 1. (num & 0xFF00) >> 8 : Move High Byte to Low Byte position
     28     // 2. (num & 0x00FF) << 8 : Move Low Byte to High Byte position
     29     
     30     swapped = ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
     31 
     32     printf("Original: %hu (Hex: 0x%04X)\n", num, num);
     33     printf("Swapped:  %hu (Hex: 0x%04X)\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