#include <stdio.h> #include <stdint.h> typedef union { uint32_t value; uint8_t bytes[4]; } Register; // Write logic here to extract bytes using union void print_bytes(uint32_t input) { // Your code here Register reg ; reg.value = input; reg.bytes[0] = uint8_t(reg.value); reg.bytes[1] = uint8_t(reg.value >> 8); reg.bytes[2] = uint8_t(reg.value >> 16); reg.bytes[3] = uint8_t(reg.value >> 24); for(int i=0;i<4;i++){ printf("%d ",reg.bytes[i]); } } int main() { uint32_t num; scanf("%u", &num); print_bytes(num); return 0; }
Test Cases
Test Results
Input
305419896
Expected Output
120 86 52 18