views:

281

answers:

2

Hello,

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 from hardware that can't pass a 32 bit value directly, but passes two consecutive 16-bit values separately.

Thanks,

+7  A: 
$a = ($a << 16) | $b;
Wrikken
+1  A: 

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
Arne