#include <stdio.h>
#include <stdint.h>
void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
// Store most significant byte first
arr[0] = (value >> 24) & 0xFF;
arr[1] = (value >> 16) & 0xFF;
arr[2] = (value >> 8) & 0xFF;
arr[3] = value & 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;
}
Big-endian transmission means the most significant byte is sent first.
This format is common in network protocols and cross-platform embedded communications.
Also note: when you pass an array to a function, you’re actually passing a pointer to its first element. So any modification made to arr inside the function will reflect in the main() function — because both refer to the same memory.
Input
305419896
Expected Output
18 52 86 120