[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Ericsson

4. Can you write a program to convert big-endian to little-endian?

Answer:

#define htons(A) ((((unit16_t)(A) & 0xff00) >> 8) | (((unit16_t)(A) & 0xff00) << 8))

#define htonl(A) ((((unit32_t)(A) & 0xff000000) >> 24) | (((unit32_t)(A) & 0x00ff0000) >> 8) | (((unit32_t)(A) & 0x0000ff00) << 8) | (((unit32_t)(A) & 0x000000ff) << 24))


---------- or
convertBigtoLittle (int num)
{
int b0,b1,b2,b3;
b0 = (num & 0x000000ff) >> 0;
b1 = (num & 0x0000ff00) >> 8;
b2 = (num & 0x00ff0000) >> 16;
b3 = (num & 0xff000000) >> 24;

return ((b0 << 24) | (b1 << 16) | (b2 << 8) | (b3 << 0))

}

Post Your Answer Here:      Public      Private

Rate This: +1 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here