unsigned long long to char array and back etc.

// 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 :slight_smile:
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;
}

TOPIC SPLIT
DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Language problem ?
Try a language closer to your native language: