views:

107

answers:

1

hey there i am trying to implement DataOutputStream in php (DataOutputStream from java language) in java code they shift right variables like this >>>

in php i can only shift like this >>

how can i do this in php ?

thank you

+4  A: 

You can implement the behavior of the unsigned right shift operator >>> with the signed shift operators like this:

The value of n>>>s is n right-shifted s bit positions with zero-extension. If n is positive, then the result is the same as that of n>>s; if n is negative, the result is equal to that of the expression (n>>s)+(2<<~s) if the type of the left-hand operand is int, and to the result of the expression (n>>s)+(2L<<~s) if the type of the left-hand operand is long. The added term (2<<~s) or (2L<<~s) cancels out the propagated sign bit.

Gumbo
so this is what i have to do private function shiftRight3($a ,$b){ if(is_numeric($a) }else{ return $a >> $b; } }
shay
@shay: Yes, exactly.
Gumbo
thank you all :)
shay
No, not exactly. All you need to do is shift and mask to the required number of bits.
EJP
hey EJP can u provide an example please ?
shay