We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
int temp 1 , temp2; temp1 = ((packet_analyze[i] << 56) & 0xFF000000); temp1 |= ((packet_analyze[i+1] << 48) & 0x00FF0000); temp1 |= ((packet_analyze[i+2] << 40) & 0x0000FF00); temp1 |= ((packet_analyze[i+3] << 32) & 0x000000FF); temp2 = ((packet_analyze[i+4] << 56)) & 0xFF000000; temp2 |= ((packet_analyze[i+5] << 48)) & 0x00FF0000; temp2 |= ((packet_analyze[i+6] << 40)) & 0x0000FF00; temp2 |= ((packet_analyze[i+7] << 32)) & 0x000000FF; printf("Source address= 0x%0.8x%0.8x\n",temp1,temp2); Expected output = 0x0af2446a20b23ff5 Output obtained = 0x000000000000000
Your shift values vastly exceed the actual width of the int type (16 bits for C51). The values all shift off the end of the type, resulting in zero, before the bitmasks are applied. (And even if they didn't, half the bitmask values are too large.) Your printf specifiers are for "ints" (16 bits" and not longs ("%lx"). Why not go for the much simpler
for (j = 0; j < 8; ++j) printf ("%bx", packet_analyze[i+j]);
printf ("%bx%bx%bx%bx%bx%bx%bx%bx\n", packet_analyze[i], packet_analyze[i+1], packet_analyze[i+2], packet_analyze[i+3], packet_analyze[i+4], packet_analyze[i+5], packet_analyze[i+6], packet_analyze[i+7] );