开发者

how to reverse this operation?

<?php

echo (2884284 >> 16), '<br>'; // = 44

echo ((2884284 >> 16) &a开发者_StackOverflow中文版mp; 0xFFFF), '<br>'; // 44

from the above i got 44

so how can i retrive from 44 to 2884284 ???


You cant. You are destroying data by doing the shift.


To expand on mhughes answer:

2884284 in binary is:

1011000000001010111100

When you shift to the right, bits to the right are cut off, and bits on the left are filled with 0. So 2884284 >> 16 becomes:

0000000000000000101100

...which, as you mentioned, is 44. Notice this is the same as dividing by 2^16 and rounding down. The reverse operation is <<, or bit shift left. It cuts off bits on the left and fills in bits on the right with zero. But 44 << 16 is:

1011000000000000000000

...that is, you lost the data from the truncated bits. This number is 2883584, which maybe is close enough. Note this is the same as multiplying by 2^16.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜