#include <stdio.h> #include <stdint.h> void convert_to_big_endian(uint32_t value, uint8_t arr[4]) { // Your code here for( char a = 0 ; a < 4 ; a++ ){ arr[a]=0; } for( char j = 0 ; j < 4 ; j++ ){ for( int i = 24 ; i<32 ; i++){ if( value & (1<<i) ){ arr[j] |= (1<<(i%8)); } else { arr[j] &= ~(1<<(i%8)); } } 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; }
Test Cases
Test Results
Input
305419896
Expected Output
18 52 86 120