I wanted to test the serial.print(value,HEX) function to make sure, that the output from the routine always are 2 chars long ( eg: 0x00 --> 00 and 0xFF --> FF).
so I wrote the following test code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
int n;
for (int n = 0; n <= 16; n++)
{
Serial.print(n,HEX);
}
Serial.println();
}
But the result(s) were not very amusing:
n = 0 --> 0 (* 1 char ) , ... n = 9 --> 9 ( 1 char ),
n = 10 --> A ( 1 char ) , n =15 --> F ( 1 char *)
the foreleading ZERO is missing.
n = 16 --> 10 ( 2 chars)
In a way the function is working fine but I want the output AS:
0 --> 00 , 1 --> 01, ... 9 --> 09 .... all with a foreleading Zero.
Is there an option in this ser.prnt(Value,HEX) command so I can force 2 digits output (eg a foreleading ZERO when value is below 0x10 ?
or is there another way to get a 2 (ASCII) chars output.
Sorry, my fault: I should have specified that the purpose of the test was to find IF I could use the ser.prnt(Value,hex) function in my project. My (very) old ISA-486 Compaq shortcircuited in the PSU and killed my EPROM-burner (Sunshine 4c). Now I have 4 * 2716 EPROM's I MUST read (and later copy that HEX-string to FLASH-RAM). SO I plan to build a new-EPROM-READER using an 2650 MEGA and was testing IF the ser.prnt(Value,hex) function was useful. (later putting the HEX-results into an Intel HEX string and later transfer that to a PC using puTTY or another FILE -supporting monitor. Sad to say - but using the ser.prnt(... DEC) option is not considered very useful, as it gives me more work on the PC-side.