#include <stdio.h> #include <stdint.h> uint32_t convert_endian(uint32_t value) { // Write logic to swap bytes uint32_t high_end = (value >> 16) & 0xFFFF; uint16_t high_hb = (high_end >> 8) & 0xff; uint16_t low_hb = (high_end) & 0xff; uint32_t low_end = (value ) & 0xFFFF; uint16_t lowe_hb = (low_end >> 8) & 0xff; uint16_t lowe_lb = (low_end) & 0xff; uint32_t low_final = ( low_hb << 8)| high_hb; uint32_t high_final = ( lowe_lb << 8)| lowe_hb; return (high_final << 16) | low_final; } int main() { uint32_t val; scanf("%u", &val); printf("%u", convert_endian(val)); return 0; }
Test Cases
Test Results
Input
305419896
Expected Output
2018915346