Code

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

void convert_to_big_endian(uint32_t value)
{
    uint8_t arr[4];

    arr[0] = (value >> 24) & 0xFF;
    arr[1] = (value >> 16) & 0xFF;
    arr[2] = (value >> 8)  & 0xFF;
    arr[3] = value & 0xFF;

    for (int i = 0; i < 4; i++)
    {
        printf("%d ",arr[i]);
    }
}

int main(void)
{
    uint32_t value;

    // Read hex input (example: 12345678)
    scanf("%d", &value);

    convert_to_big_endian(value);
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

305419896

Expected Output

18 52 86 120