fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. void convertUint16ToUint8(uint16_t* tempArray, uint8_t* tempBuffer, size_t length) {
  5. for (size_t i = 0; i < length; i++) {
  6. tempBuffer[2 * i] = (uint8_t)(tempArray[i] >> 8); // High byte
  7. tempBuffer[2 * i + 1] = (uint8_t)(tempArray[i] & 0xFF); // Low byte
  8. }
  9. }
  10.  
  11. int main() {
  12. uint16_t tempArray[8] = {0x1234, 0x5678, 0x9ABC, 0xDEF0, 0x1122, 0x3344, 0x5566, 0x7788};
  13. uint8_t tempBuffer[16];
  14.  
  15. convertUint16ToUint8(tempArray, tempBuffer, 8);
  16.  
  17. // Print the result
  18. for (int i = 0; i < 16; i++) {
  19. printf("%02X ", tempBuffer[i]);
  20. }
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
12 34 56 78 9A BC DE F0 11 22 33 44 55 66 77 88