Union Extract Bytes from a 32-bit Value

Code

#include <stdio.h>
#include <stdint.h>

typedef union{
    uint32_t reg; 
    uint8_t byte[4]; 
}Extract_byte; 


int main(){
    Extract_byte value; 
    scanf("%u", &value.reg); 
    for(uint8_t i = 0; i<4; i++){
        printf("%hhu ", value.byte[i]); 
    }
    
    return 0;
} 

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

305419896

Expected Output

120 86 52 18