convert binary to hexadecimal

Can I type input Binary and convert to Hexadecimal ?

and

Can I type input Hexadecimal and convert to Binary ?

Input By Serial monitor*

Code receive Integer DEC and show on serial monitor

void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available() == 0);
int x = Serial.parseInt(); //read int or parseFloat for ..float...
Serial.print(x);
Serial.print("\t");
Serial.print(x,BIN);
Serial.print("\t");
Serial.print(x,OCT);
Serial.print("\t");
Serial.print(x,DEC);
Serial.print("\t");
Serial.println(x,HEX);
Serial.println("");
}

Well if you type in 1001, parseInt will read one thousand and one, not a binary number whose value would be 9

So then what you print would be the binary or hex representation of one thousand and one

Makes sense?

If you want to type in binary you need to read the string and parse and build up your integer representation so that 1001 is actually 9 in decimal

Maybe this could help a bit? ...click here...

Binary number system is a base 2 number system using digits 0 and 1 whereas Hexadecimal number system is base 16 and using digits from 0 to 9 and A to F. Given a binary number as input from user convert it to hexadecimal number. Check this c program to convert binary number to hexadecimal number. Hope it helps.