Data Transmission

Code

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    for(uint8_t i =4 ; i >0; i--)
    {
        uint8_t bit_LOW = 0;
        uint8_t bit_HIGH = 0;
        bit_LOW = value & 0x0F;
        value = value >> 4 ;
        bit_HIGH = value & 0x0F;
        arr[i-1]= (bit_HIGH<<4) | bit_LOW;
        value = value >> 4;
    }
}

int main() {
    uint32_t value;
    uint8_t arr[4];
    scanf("%u", &value);
    convert_to_big_endian(value, arr);
    for (int i = 0; i < 4; i++) {
        printf("%u", arr[i]);
        if(i<3){
            printf(" ");
        }
    }
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

305419896

Expected Output

18 52 86 120