luc108.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Receive an 8-bit number and exchange its higher 4 bits with lower 4 bits.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char num, swapped;
printf("Enter an 8-bit number (0-255): ");
scanf("%hhu", &num);
// Exchange nibbles
// (num & 0xF0) >> 4 : High nibble to Low
// (num & 0x0F) << 4 : Low nibble to High
swapped = ((num & 0xF0) >> 4) | ((num & 0x0F) << 4);
printf("Original: %d (Hex: 0x%02X)\n", num, num);
printf("Swapped: %d (Hex: 0x%02X)\n", swapped, swapped);
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21