Code

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    int j=3;
    int k=100;
    for(uint32_t i=0;i<4;i++)
    {
       uint32_t pos=i*8;
       uint32_t len=(1<<8)-1;
       arr[j]=(value>>pos)& len;
        j=j-1;

        // printf("%d\n",pos);
    //    value=value

    }
}

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