All submissions

Little Endian to Big Endian

Code

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

inline void swap(char* byte_arr, uint8_t i, uint8_t j)
{
    char temp = byte_arr[i];
    byte_arr[i] = byte_arr[j];
    byte_arr[j] = temp;
}

uint32_t convert_endian(uint32_t value) {
    // Write logic to swap bytes
    char* byte_arr = (char*) &value;
    swap(byte_arr, 0, 3);
    swap(byte_arr, 1, 2);

    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