#include <stdio.h> #include <stdint.h> typedef union { uint32_t word; uint8_t bytes[4]; } word_t; uint32_t convert_endian(uint32_t value) { word_t word; word.word = value; uint8_t temp; int i; for(i = 0; i < 2; i++){ temp = word.bytes[i]; word.bytes[i] = word.bytes[3 - i]; word.bytes[3 - i] = temp; } return word.word; } int main() { uint32_t val; scanf("%u", &val); printf("%u", convert_endian(val)); return 0; }
Test Cases
Test Results
Input
305419896
Expected Output
2018915346