All submissions

Little Endian to Big Endian

Code

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

typedef union {
    uint32_t value;
    uint8_t bytes[4];
} Reg32;

uint32_t convert_endian(uint32_t value) {
    Reg32 reg;
    uint8_t cur_byte;

    reg.value= value; 

    cur_byte = reg.bytes[0];
    reg.bytes[0] = reg.bytes[3];
    reg.bytes[3] = cur_byte;

    cur_byte = reg.bytes[1];
    reg.bytes[1]= reg.bytes[2];
    reg.bytes[2]= cur_byte ;

    return reg.value;
}

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




 

Loading...

Input

305419896

Expected Output

2018915346