C Program to Convert Binary to Hexadecimal 1

#include<stdio.h>

int main(){

printf(“Enter any number any binary number: “);

scanf(“%ld”,&binaryNumber);

while(binaryNumber!=0){

remainder=binaryNumber%10;

j=j*2;

binaryNumber=binaryNumber/10;

}

return 0;

}

Sample output:

Enter any number any binary number: 1101

How to convert large binary number to hexadecimal

#include<stdio.h>

#define MAX 1000

int main(){

int temp;

long int i=0,j=0;

printf(“Enter any number any binary number: “);

scanf(“%s”,binaryNumber);

while(binaryNumber[i]){

binaryNumber[i] = binaryNumber[i] -48;

++i;

}

–i;

while(i-2>=0){

temp =  binaryNumber[i-3] *8 + binaryNumber[i-2] *4 +  binaryNumber[i-1] *2 + binaryNumber[i] ;

if(temp > 9)

else

i=i-4;

}

if(i ==1)

hexaDecimal[j] = binaryNumber[i-1] *2 + binaryNumber[i] + 48 ;

else if(i==0)

hexaDecimal[j] =  binaryNumber[i] + 48 ;

else

–j;

while(j>=0){

}

return 0;

}

Sample output:

Enter any number any binary number: 1010011011100011110

001001111011110001000100011101110111011110

Algorithm:

Step1: Arrange the binary number in the group 4 from right side.

Step 2:  Replace the each group with following values:

 Binary number Hexadecimal values 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F