programming-examples/c++/Basic/Binary to Hexadecimal.cpp

17 lines
459 B
C++
Raw Normal View History

2019-11-18 14:44:36 +01:00
#include < iostream.h>
int main()
{
long int binaryval, hexadecimalval = 0, i = 1, remainder;
cout<<"Enter the binary number: ";
cin>>binaryval;
while (binaryval != 0)
{
remainder = binaryval % 10;
hexadecimalval = hexadecimalval + remainder * i;
i = i * 2;
binaryval = binaryval / 10;
}
cout<<"Equivalent hexadecimal value:"<<hexadecimalval;
return 0;
}