Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C Program to Convert Hexadecimal to Binary
✅ C Program to Convert Hexadecimal to Binary (Using Bitwise Operators)
#include <stdio.h>
int main() {
int num;
printf("Enter a hexadecimal number: ");
scanf("%x", &num); // read hex directly into int
printf("Binary: ");
for (int i = 31; i >= 0; i--) {
int bit = (num >> i) & 1;
printf("%d", bit);
}
printf("\n");
return 0;
}
๐ Explanation:
This program converts a hexadecimal number into its binary form using bitwise operators.
scanf("%x", &num)→ directly reads a hexadecimal number into an integer.(num >> i) & 1→ extracts the i-th bit from the number.- Loop runs from bit 31 to 0 → prints all 32 bits (full binary representation).
- Output shows the binary form padded to 32 bits.
๐งพ Sample Output:
Enter a hexadecimal number: 1A Binary: 00000000000000000000000000011010 Enter a hexadecimal number: FF Binary: 00000000000000000000000011111111
๐ Keywords:
C program hex to binary, hexadecimal to binary conversion, bitwise operators in C, scanf %x example, binary representation in C
๐ Hashtags:
#CProgramming #HexToBinary #BitwiseOperators #CodingForBeginners #InterviewQuestions
๐ Search Description:
This C program converts hexadecimal to binary using bitwise operators. It reads hex with %x and prints the 32-bit binary representation.
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment