24. Data Transmission

Back To All Submissions
Previous Submission
Next Submission

Code

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

void convert_to_big_endian(uint32_t value, uint8_t arr[4]) {
    // Your code here
    uint32_t temp=value;
    // temp=temp&((1<<8)-1);
    int index=3;
    int pos=0;
    for(int i=8;i<=32;i=i+8)
    {
        temp=value;
        temp=temp>>pos;
        arr[index]=temp&(((1<<i)-1));
        index--;
        pos=pos+8;
    }
    arr[0]=(value>>24);
}

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

 

 

 

Was this helpful?
Upvote
Downvote