## Pages

### binary to hexadecimal conversion in c language | CTechnotips

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

For example we want to convert binary number 11011010101001101 to hexadecimal.

Step 1: 0001 1011 0101 0100 1101
Step 2:  1     B    5    4   D

So (1011010101001101)2 = (1B54D)16

C program for hexadecimal to binary conversion

#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