Skip to content

Commit 264fd91

Browse files
authored
added binary to hexadecimal conversion
1 parent 2d376fb commit 264fd91

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

conversions/binary2hexa.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* C Program to Convert Binary to Hexadecimal
3+
*/
4+
#include <stdio.h>
5+
6+
int main()
7+
{
8+
long int binary, hexa = 0, i = 1, remainder;
9+
10+
printf("Enter the binary number: ");
11+
scanf("%ld", &binary);
12+
while (binary != 0)
13+
{
14+
remainder = binary % 10;
15+
hexa = hexa + remainder * i;
16+
i = i * 2;
17+
binary = binary / 10;
18+
}
19+
printf("THe Equivalent hexadecimal value: %lX", hexa);
20+
return 0;
21+
}

0 commit comments

Comments
 (0)