All submissions

Code

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

//use it to splice a single 32 bit data to four 8 bit data
union datatype_new{
    uint32_t new_val;
    uint8_t new_arr[4];
}tx_buff;


void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    tx_buff.new_val = value;
    uint8_t x;
    for(x = 0; x < 4; x++)
    {
        arr[x] = tx_buff.new_arr[3 - x];
    }

}

int main() {
    uint32_t value;
    uint8_t arr[4];
    scanf("%u", &value);
    convert_to_big_endian(value, arr);
    for (int i = 0; i < 4; i++) {
        printf("%u", arr[i]);
        if(i<3){
            printf(" ");
        }
    }
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

305419896

Expected Output

18 52 86 120