Write a C program to input binary number from user and convert to hexadecimal number system. How to convert binary to hexadecimal number system in C program. Logic to convert binary to hexadecimal number system in C programming.
Example
Input
Enter binary number: 11000010
Output
Hexadecimal: C2
Required knowledge
Basic C programming, If else, While loop, For loop, Nested loop, Array
Must know – Program to find last digit
Binary number system
Binary number system is a base 2 number system. Binary number system uses only two symbols to represent all its values i.e. 0
and 1
Hexadecimal number system
Hexadecimal number system is base 16 number system. Hexadecimal number system uses 16 symbols to represent all its values i.e. 0123456789ABCDEF
Logic to convert binary to hexadecimal number system
Binary to hexadecimal conversion algorithm is divided in two parts.
- Group all binary bits to 4 digits starting from right side.
- Write corresponding hexadecimal value of each grouped digit.
Binary to hexadecimal conversion table
Decimal | Binary | Hexadecimal |
---|---|---|
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
Program to convert binary to hexadecimal number system
Output
Enter binary number: 01101110 Binary number = 1101110 Hexadecimal number = 6E
Happy coding
Recommended posts
- Loop programming exercises and solutions in C.
- C program to find one’s complement of a binary number.
- C program to convert Binary to Octal number system.
- C program to convert Binary to Decimal number system.
- C program to convert Hexadecimal to Binary number system.
- C program to convert Hexadecimal to Octal number system.
- C program to convert Hexadecimal to Decimal number system.