Hi i have an Arduino mega 2560 i send data from the Arduino over USB to PC. That works when i test a simple Serial.print("Hello"); but that is not that what i need. I send a timestamp as a longe Value and the databyte as a short Value. When i send the timestamp as BIN like that:
void sendBinaryValue(short incomingByte)
{
int temp = (incomingByte & 0xFF00)>>8;
Serial.println(temp, HEX);
temp = (incomingByte & 0x00FF);
Serial.println(temp, HEX);
return;
}
void sendBinaryTime(unsigned long currentMillis)
{
int temp = (currentMillis & 0xFF000000)>>24;
Serial.print(temp, BIN);
temp = (currentMillis & 0x00FF0000)>>16;
Serial.print(temp, BIN);
temp = (currentMillis & 0x0000FF00)>>8;
Serial.print(temp, BIN);
temp = (currentMillis & 0x000000FF);
Serial.print(temp, BIN);
return;
}
All is fine i haven´t any error. But i want the timestamp as DEC so i have changed the code to:
void sendBinaryValue(short incomingByte)
{
int temp = (incomingByte & 0xFF00)>>8;
Serial.println(temp, HEX);
temp = (incomingByte & 0x00FF);
Serial.println(temp, HEX);
return;
}
void sendBinaryTime(unsigned long currentMillis)
{
int temp = (currentMillis & 0xFF000000)>>24;
Serial.print(temp, DEC);
temp = (currentMillis & 0x00FF0000)>>16;
Serial.print(temp, DEC);
temp = (currentMillis & 0x0000FF00)>>8;
Serial.print(temp, DEC);
temp = (currentMillis & 0x000000FF);
Serial.print(temp, DEC);
return;
}
Now when i look on the serial monitor i get an error.
Here you can see it:

I send an A as ASCII sign that must be Hex 41 and i receive a Hex 5 but why? When i send the timestamp as BIN i get the 41 and haven´t any problem.
I hope someone can help me with friendly wishes sniffi