All submissions

Little Endian to Big Endian

Code

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

typedef union con
{
    uint32_t val;
    uint8_t byte[4];
}conv;
uint32_t convert_endian(uint32_t value) {
    // Write logic to swap bytes
    conv reg;
    uint8_t temp;

    reg.val = value;

    temp = reg.byte[0];
    reg.byte[0] = reg.byte[3];
    reg.byte[3] = temp;

    temp = reg.byte[1];
    reg.byte[1] = reg.byte[2];
    reg.byte[2] = temp;

    
    return reg.val;
}

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

Solving Approach


 

Loading...

Input

305419896

Expected Output

2018915346