Little Endian to Big Endian

Code

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

uint32_t convert_endian(uint32_t value) {
    // Write logic to swap bytes
    uint32_t a = value & 0xFF;
    uint32_t b = (value & 0xFF00) >> 8;
    uint32_t c = (value & 0xFF0000) >> 16;
    uint32_t d = (value & 0xFF000000) >> 24;

    return (a << 24) | (b << 16) | (c << 8) | d;
}

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