C Program to Convert Binary to Hexadecimal

#include <stdio.h>
#include<conio.h>
void main()
{
    clrscr();
     long int binary_num, hexa_decimal_num=0;
     int i=1, rem;
     printf("\n Enter the binary number:");
     scanf("%ld",&binary_num);

     while(binary_num!=0)
     {
          rem = binary_num % 10;
          hexa_decimal_num = hexa_decimal_num + rem * i;
          i = i * 2;
          binary_num = binary_num / 10;
     }

     printf("\n Equivalent Octal value = %lX", hexa_decimal_num);

     getch();
}

Run1:
Run2:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...