All submissions

Code

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

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

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

can be done using simpler assignment by shifting and anding with 0xff. shift by required value to get the required bit position.

 

 

Loading...

Input

305419896

Expected Output

18 52 86 120