All submissions

Union Extract Bytes from a 32-bit Value

Code

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

// Write logic here to extract bytes using union
typedef union {
    uint32_t value;
    struct{
        uint8_t byte1: 8;
        uint8_t byte2: 8;
        uint8_t byte3: 8;
        uint8_t byte4: 8;
    }extract;
} Register;



void print_bytes(uint32_t input) {
    // Your code here
    Register reg;
    reg.value = input;
    printf("%u ", reg.extract.byte1);
     printf("%u ", reg.extract.byte2);
      printf("%u ", reg.extract.byte3);
       printf("%u ", reg.extract.byte4);

   
}

int main() {
    uint32_t num;
    scanf("%u", &num);
    print_bytes(num);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

305419896

Expected Output

120 86 52 18