All submissions

Data Transmission

Code

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    uint32_t  i;
    for (i=0; i < 4; i++) {
        arr[3-i] = (value & 0xFF); 
        value = (value >> 8);
    }
}

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

 

for big endian start from the right, isolate the eight bits, 

then fill the array in reverse

 

Loading...

Input

305419896

Expected Output

18 52 86 120