All submissions

 

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    // arr[0] = (value >> 24) & 0xFF;
    // arr[1] = (value >> 16) & 0xFF;
    // arr[2] = (value >> 8)  & 0xFF;
    // arr[3] = value & 0xFF;
    // Loop through 4 bytes (from MSB to LSB)
    for (int i = 0; i < 4; i++) 
    {
    // Shift the value right by (24, 16, 8, 0) bits for i = 0 to 3 respectively 
    arr[i] = (value >> (8 * (3 - i))) & 0xFF; // mask with 0xFF to extract only the current byte
    }
}

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;
}

 

 

 

 

Loading...

Input

305419896

Expected Output

18 52 86 120