#include <stdio.h> #include <stdint.h> /* Plan: Cut up the value into 4 bytes of data (4 number) Big Endian input = 0xdeadbeef 0xde 0xad 0xbe 0xef (input & (0xFF000000))>>3 * 8 (input & (0x00FF0000))>>2 * 8 (input & (0x0000FF00))>>1 * 8 (input & (0x000000FF))>>0 * 8 */ void convert_to_big_endian(uint32_t value, uint8_t arr[4]) { // Your code here arr[0] = (value & (0xFF000000))>>24; arr[1] = (value & (0x00FF0000))>>16; arr[2] = (value & (0x0000FF00))>>8; arr[3] = (value & (0x000000FF))>>0; } 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