#include <stdio.h>
#include <stdint.h>
void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
// Your code here
for(int i=3;i>=0;i--){
arr[i]=(value&0xFF);
value=value>>8;
}
}
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
just shift the bits out (8 places) and take AND with FF , store this result in the array location , Big Endian means LSB ,--> higher memory address, MSB -->lower memory address .