2018-01-28 21:15:09 +08:00
|
|
|
/*
|
2020-05-30 04:23:24 +08:00
|
|
|
* C Program to Convert Binary to Hexadecimal
|
2018-01-28 21:15:09 +08:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2020-05-30 04:23:24 +08:00
|
|
|
|
2018-01-28 21:15:09 +08:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
long int binary, hexa = 0, i = 1, remainder;
|
2020-05-30 04:23:24 +08:00
|
|
|
|
2018-01-28 21:15:09 +08:00
|
|
|
printf("Enter the binary number: ");
|
|
|
|
scanf("%ld", &binary);
|
|
|
|
while (binary != 0)
|
|
|
|
{
|
|
|
|
remainder = binary % 10;
|
|
|
|
hexa = hexa + remainder * i;
|
|
|
|
i = i * 2;
|
|
|
|
binary = binary / 10;
|
|
|
|
}
|
2020-10-30 05:25:36 +08:00
|
|
|
printf("The equivalent hexadecimal value: %lX", hexa);
|
2018-01-28 21:15:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|