I am trying to combine two integers in my application. By combine I mean stick one byte stream at the end of the other, not concatenate the strings.
The two integers are passed fro开发者_如何转开发m hardware that can't pass a 32 bit value directly, but passes two consecutive 16-bit values separately.
Thanks,
$a = ($a << 16) | $b;
I have no idea of the syntax in PHP, but I bet it supports bitwise operators.
You can shift the first 16 bit integer to the left and add it to the second 16 bit integer:
first integer:
0000000000000001
second integer:
0000000000000010
shift first to the left by, say, 16:
first integer:
00000000000000010000000000000000
second integer:
0000000000000010
add them:
00000000000000010000000000000010
精彩评论