True. Since the answer was trivial and you provided it back in Post #4, there was plenty of time for the topic to meander ![]()
Another option is to use a struct:
struct __attribute__ ((__packed__)) KeyStruct_t {
uint8_t key[14];
uint32_t randomnumber1;
uint32_t randomnumber2;
uint8_t otherpartofkey[6];
};
constexpr size_t structSize = sizeof(KeyStruct_t);
void setup() {
Serial.begin(115200);
delay(3000);
Serial.printf("structSize: %d\n", structSize);
KeyStruct_t theKey;
for (uint8_t i = 0; i < 0x0E; i++) {
theKey.key[i] = i;
}
theKey.randomnumber1 = 0x11223344;
theKey.randomnumber2 = 0x55667788;
for (uint8_t i = 0x0E; i < 0x14; i++) {
theKey.otherpartofkey[i - 0x0E] = i;
}
const uint8_t *bytePtr = reinterpret_cast<const uint8_t *>(&theKey);
for (uint8_t i = 0; i < structSize; i++) {
Serial.printf("%.2hhX ", *bytePtr++);
}
Serial.println();
}
void loop() {
}
Output:
structSize: 28
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 44 33 22 11 88 77 66 55 0E 0F 10 11 12 13