Little Endian to Big Endian

Code

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

uint32_t convert_endian(uint32_t val) {
    uint32_t result = (((0x000000FF & val) << 24)|((0x0000FF00 & val) << 8)|((0x00FF0000 & val) >> 8)|((0xFF000000 & val) >> 24));
    return result;
    // Write logic to swap bytes
    return 0;
}

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

Solving Approach


 

Upvote
Downvote
Loading...

Input

305419896

Expected Output

2018915346