114. Little Endian to Big Endian

Back To All Submissions
Previous Submission
Next Submission

Code

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

uint32_t convert_endian(uint32_t value) {

    return ((value >> 24) & 0x000000FF) |
           ((value >> 8)  & 0x0000FF00) |
           ((value << 8)  & 0x00FF0000) |
           ((value << 24) & 0xFF000000);
}

int main() {
    uint32_t val;

    scanf("%u", &val);

    printf("%u", convert_endian(val));

    return 0;
}

Solving Approach


 

Was this helpful?
Upvote
Downvote