12 C Program to Convert Binary to Hexadecimal
Posted by Superadmin on December 22 2015 03:12:54
This C Program Converts the given Binary to Hexadecimal . Binary number is a number that can be represented using only two numeric symbols – 0 and 1. A number in base 2. Hexadecimal is base 16 arithmetic where each digit is a value from 0 to 15, rather than the 0-9 of base 10.
Here is source code of the C program to Convert Binary to Hexadecimal . The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Convert Binary to Hexadecimal
*/
#include <stdio.h>
int main()
{
long int binaryval, hexadecimalval = 0, i = 1, remainder;
printf("Enter the binary number: ");
scanf("%ld", &binaryval);
while (binaryval != 0)
{
remainder = binaryval % 10;
hexadecimalval = hexadecimalval + remainder * i;
i = i * 2;
binaryval = binaryval / 10;
}
printf("Equivalent hexadecimal value: %lX", hexadecimalval);
return 0;
}
Output:
$ cc pgm7.c
$ a.out
Enter the binary number: 10000
Equivalent hexadecimal value: 10