// Arduino IDE 1.8.8
/*
phänomen, dieser Blödsinn sollte eigentlich gar nicht laufen.
Tut er (der Blödsinn) aber , keine Ahnung warum.
Kann mir jemand erklären wieso der Serial Monitor wunschgemäß uint32_t mit leading ZERO anzeigt?
Obwohl der code absolut falsch ist?
Es dürften eigentlich nut 4 Nullen angezeigt werden.
this nonsense shouldn't actually work.
but it does, ……………. no idea why.
Can anyeone explain me why the Serial Monitor displays correctly the uint32_t with leading ZEROs?
Although the code is absolutely wrong?
*/
uint32_t val32 = 0x123456;
void setup() {
Serial.begin(9600);
}
void loop() {
int32toASCIIHEX(val32, 8 );
Serial.println();
delay(1000);
}
void int32toASCIIHEX(uint32_t val, byte digits) { // with leading ZEROs
String(val32, HEX); // makes no sense, but it makes the Code doing well
int NumberOfZeros = digits - NumberOfDigits(val, HEX);
char ZERO[NumberOfZeros];
for (int i = 0; i < NumberOfZeros; i++) {
ZERO[ i ] = '0'; // just '0' and Nothing else
}
Serial.println(ZERO); // print shows the same as write???
Serial.write(ZERO); // write shows the same as print???
Serial.println();
}
byte NumberOfDigits(uint32_t val, byte base) {
byte count = 0;
while (val) {
val = val / base;
count++;
}
return count;
}