All submissions

Little Endian to Big Endian

Code

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

typedef union 
{
    uint32_t value;
    uint8_t v[4];
}indian_s;

uint32_t convert_endian(uint32_t value) {
    indian_s ms;
    ms.value = value;
    uint8_t temp_a  = ms.v[0];
    uint8_t temp_b  = ms.v[1];
    uint8_t temp_c  = ms.v[2];
    uint8_t temp_d  = ms.v[3];
    ms.v[3] = temp_a;
    ms.v[2] = temp_b;
    ms.v[1] = temp_c;
    ms.v[0] = temp_d;
    return ms.value;
}

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

Solving Approach


 

Loading...

Input

305419896

Expected Output

2018915346