Write a C++ program to convert given binary number to Hexadecimal number.
Program Code:
#include<iostream>
using namespace std;
int main()
{
long int binary, rem, q;
int i=1, j, temp;
char hexa[100];
cout<<"Enter Binary Number : ";
cin>>binary;
q = binary;
while(q != 0)
{
temp = q % 16;
// To convert integer into character
if( temp < 10)
{
temp = temp + 48;
}
else
{
temp = temp + 55;
}
hexa[i++]= temp;
q = q / 16;
}
cout<<"Equivalent hexadecimal value of "<<binary <<" is : ";
for(j=i-1 ;j>0;j--)
{
cout<<hexa[j];
}
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter Binary Number : 12
Equivalent hexadecimal value of 12 is : C
Thanks
Mukesh Rajput
Post A Comment:
0 comments: