Code

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


// BIG ENDIAN: 0x123456
// 0x0: 0x12
// 0x1: 0x34
// 0x2: 0x56
// 0x3: 0x78
void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    for(int i=0;i<4;i++) { // 0 1 2 3
        arr[i]=(uint8_t)((value>>((3-i)*8))&0xFF);
    }
}

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

 

 

 

Upvote
Downvote
Loading...

Input

305419896

Expected Output

18 52 86 120