All submissions

Little Endian to Big Endian

Code

#include <stdio.h>
#include <stdint.h>

uint32_t convert_endian(uint32_t value) {
    // Write logic to swap bytes
    return ((value >> 24) & 0x000000FF) | // move byte 3 to byte 0
           ((value >> 8)  & 0x0000FF00) | // move byte 2 to byte 1
           ((value << 8)  & 0x00FF0000) | // move byte 1 to byte 2
           ((value << 24) & 0xFF000000);  // move byte 0 to byte 3
}

int main() {
    uint32_t val;
    scanf("%u", &val);
    printf("%u", convert_endian(val));
    return 0;
}

Solving Approach


 

Loading...

Input

305419896

Expected Output

2018915346