TheAlgorithms-C/conversions/binary_to_hexadecimal.c

22 lines
455 B
C
Raw Normal View History

2018-01-28 16:15:09 +03:00
/*
* C Program to Convert Binary to Hexadecimal
2018-01-28 16:15:09 +03:00
*/
#include <stdio.h>
2018-01-28 16:15:09 +03:00
int main()
{
long int binary, hexa = 0, i = 1, remainder;
2018-01-28 16:15:09 +03: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;
}
printf("The equivalent hexadecimal value: %lX", hexa);
2018-01-28 16:15:09 +03:00
return 0;
}