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
Binary to Hexadecimal Conversion in C
✅ Binary to Hexadecimal Conversion in C
#include<stdio.h>
int main( )
{
int num, hexa = 0, remainder, j = 1;
printf("Enter the binary number:\n");
scanf("%d", &num);
while(num != 0)
{
remainder = num % 10;
hexa = hexa + remainder * j;
j = j * 2;
num = num / 10;
}
printf("The hexadecimal value is %X\n", hexa);
}
๐ Explanation:
This C program converts a binary number (input as an integer) to its hexadecimal equivalent.
The binary number is first converted to its decimal form manually using bit-weight multiplication (base 2 logic).
The resulting decimal is then printed in hexadecimal using the format specifier %X.
๐งพ Sample Output:
Enter the binary number: 1010 The hexadecimal value is A
๐ Keywords:
Binary to Hexadecimal, C Program for Hex Conversion, base conversion in C, Hexadecimal output, %X format specifier, scanf printf in C
๐ Hashtags:
#CProgramming #BinaryToHex #HexadecimalConversion #BaseConversion #PrintfFormat #BeginnerCCode #BitwiseLogic
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