hex - Convert little endian to big endian including 0 (zero) -


im trying convert little endian big endian , having trouble. have array has 2 bytes of unsigned char hex values. , make big endian zeros gone , cant values want.

for example, goal get

array[0] = 0b array[1] = 40 output = 0b40 can see value 2880 when %d 

so used

output = (array[1]>>4) | (array[0]<<4); 

but in reality, see

printf("output = %x04\n", output); output = 00b4 

i want output 0b40 can 2880 when do

printf("output = %x\n", output); output = 0b40  printf("output = %d\n", output); output = 2880 

thanks guys appreciated

you need shift bottom 8 bits, not four, , not shift top:

output = (array[0]<<8) | array[1]; 

see convert big endian little endian in c more discussion , code.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -