Little Endian to Big Endian

EZ task

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

uint32_t convert_endian(uint32_t value) {
    uint32_t a,b,c,d,res;
    a= (value & 0xFF000000) >> 24;
    b= (value & 0x00FF0000) >> 8;
    c= (value & 0x0000FF00) << 8;
    d= (value & 0x000000FF)   << 24;
    res = d | c | b | a;
    return res;
}

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