Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Test casting uint16_t array to uint8_t array
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdint.h> //for uints
- void printBuffer16 (uint16_t *buffer, size_t size);
- void printBuffer8 (uint8_t *buffer, size_t size);
- int main(){
- uint16_t buffer []={0x1234,0x5678,0x9ABC}; //uint16_t array
- printBuffer16(buffer,sizeof buffer/sizeof (buffer[0]));
- //Casting uint16_t array to uint8_t array
- printBuffer8((uint8_t*) buffer,sizeof buffer/sizeof (buffer[0]));
- return 0;
- }
- void printBuffer16 (uint16_t *buffer, size_t size){
- for (int i=0;i<size ;i++){
- printf ("0x%X\n",*buffer);
- buffer++;
- }
- }
- void printBuffer8 (uint8_t *buffer, size_t size){
- for (int i=0;i<size*2 ;i++){
- printf ("0x%X\n",*buffer);
- buffer++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement