Advertisement
AntonioVillanueva

test casting uint16_t array to uint8_t array

Jun 15th, 2022
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. /*
  2.  * Test casting uint16_t array to uint8_t array
  3.  */
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #include <stdint.h> //for uints
  8.  
  9. void printBuffer16 (uint16_t *buffer, size_t size);
  10.  
  11. void printBuffer8 (uint8_t *buffer, size_t size);
  12.  
  13. int main(){
  14.     uint16_t buffer []={0x1234,0x5678,0x9ABC}; //uint16_t array
  15.  
  16.     printBuffer16(buffer,sizeof buffer/sizeof (buffer[0]));
  17.    
  18.     //Casting uint16_t array to uint8_t array
  19.     printBuffer8((uint8_t*) buffer,sizeof buffer/sizeof (buffer[0]));
  20.     return 0;
  21. }
  22.  
  23.  
  24. void printBuffer16 (uint16_t *buffer, size_t size){
  25.    
  26.     for (int i=0;i<size ;i++){     
  27.         printf ("0x%X\n",*buffer);
  28.         buffer++;
  29.     }  
  30. }
  31.  
  32. void printBuffer8 (uint8_t *buffer, size_t size){
  33.    
  34.     for (int i=0;i<size*2 ;i++){       
  35.         printf ("0x%X\n",*buffer);
  36.         buffer++;
  37.     }
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement