WAP in C to Convert Binary Number into Hexadecimal Number?

#include <stdio.h>
#include<conio.h>
int main()
{
long int bval, hval = 0, i = 1, rem;
clrscr();
printf(“Enter the binary number: “);
scanf(“%ld”, &bval);
while (bval != 0)
{
rem = bval % 10;
hval = hval + rem * i;
i = i * 2;
bval = bval / 10;
}
printf(“Equivalent hexadecimal value: %lX”, hval);
getch();
return(0);
}

Output :-

BinToHex.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s