fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <stdio.h>
  9. #include <stdint.h>
  10.  
  11. #define NUM_SAMPLES 8
  12. #define DMA_DATA_ALIGN_LSB 0
  13. #define DMA_DATA_ALIGN_MSB 1
  14.  
  15. int main() {
  16. // Simulated 16-bit input data
  17. uint16_t input_data[NUM_SAMPLES] = {0x1234, 0xABCD, 0x00FF, 0x8001, 0x5678, 0xFFFF, 0x0001, 0x7FFF};
  18.  
  19. // Output buffer for 32-bit converted data
  20. uint32_t output_data[NUM_SAMPLES];
  21.  
  22. // Simulated DMA alignment setting
  23. uint16_t dma_data_align = DMA_DATA_ALIGN_MSB; // Change to DMA_DATA_ALIGN_LSB to test other case
  24. uint16_t shift_factor = (dma_data_align == DMA_DATA_ALIGN_LSB) ? 0 : 16;
  25.  
  26. // Conversion loop
  27. for (int i = 0; i < NUM_SAMPLES; i++) {
  28. uint16_t src = input_data[i];
  29. uint32_t converted = ((uint32_t)src) << shift_factor;
  30. output_data[i] = converted;
  31.  
  32. // Print results
  33. printf("Sample %d: 16-bit = 0x%04X → 32-bit = 0x%08X\n", i, src, converted);
  34. }
  35.  
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0.01s 5288KB
stdin
45
stdout
Sample 0: 16-bit = 0x1234 → 32-bit = 0x12340000
Sample 1: 16-bit = 0xABCD → 32-bit = 0xABCD0000
Sample 2: 16-bit = 0x00FF → 32-bit = 0x00FF0000
Sample 3: 16-bit = 0x8001 → 32-bit = 0x80010000
Sample 4: 16-bit = 0x5678 → 32-bit = 0x56780000
Sample 5: 16-bit = 0xFFFF → 32-bit = 0xFFFF0000
Sample 6: 16-bit = 0x0001 → 32-bit = 0x00010000
Sample 7: 16-bit = 0x7FFF → 32-bit = 0x7FFF0000