All submissions

Code

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) 
{
    unsigned char *ptr=(unsigned char *)(&value);
    ptr+=3; //We are pointing the pointer to MSB byte so that we get all the data in th order of MSB to LSB.
    for(int i=0;i<4;i++)
    {
        arr[i]=(uint8_t)(*ptr); //everytime we dereference and update into each member of the array.
        ptr--;
    }
}

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

 

 

 

Loading...

Input

305419896

Expected Output

18 52 86 120