All submissions

Little Endian to Big Endian

Code

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

uint32_t convert_endian(uint32_t value) {
    // Write logic to swap bytes
    uint8_t *b1;
    uint8_t temp;
    b1 = (uint8_t *)&value;
    for (int i = 0; i < sizeof(value)/2; i++) {
        temp = *(b1 + sizeof(value)-1 - i);
        *(b1 + sizeof(value)-1 - i) = *(b1 + i);
        *(b1 + i) = temp;
    }
    return value;
}

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

Solving Approach


 

Loading...

Input

305419896

Expected Output

2018915346