-->
Showing posts with label binary to hexadecimal conversion. Show all posts
Showing posts with label binary to hexadecimal conversion. Show all posts

program to convert binary no. to hexadecimal number system.

//program to convert binary no. to hexadecimal number system.
#include<stdio.h>
#include<conio.h>
void main()
{
   
    long int binary_Number,hexadecimalNumber=0,j=1,remainder;
   
    printf("Enter any number any binary number: ");
    scanf("%ld",&binary_Number);
   
    while(binary_Number!=0)
{
    remainder=binary_Number%10;
    hexadecimalNumber=hexadecimalNumber+remainder*j;
        j=j*2;
        binary_Number=binary_Number/10;
      }

    printf("Equivalent hexadecimal value: %lX",hexadecimalNumber);

    getch();

}

-----------------------------------------------------------------------
logics in mind:-

->we have to input a binary number, say 111
->we make group of 3 bits from right side, and for this, we use 

hexdecimalNumber=hexadecimalNumber+remainder*j;