PHP右移 [英] PHP shift right
问题描述
嘿
我试图在PHP实现DataOutputStream类
(DataOutputStream类从Java语言)
在java中code,他们右移变量,像这样>>>
hey there i am trying to implement DataOutputStream in php (DataOutputStream from java language) in java code they shift right variables like this >>>
在PHP我只能转向像这样>>
in php i can only shift like this >>
我怎样才能做到这一点在PHP?
how can i do this in php ?
感谢您
推荐答案
可以的实施无符号向右移位运算符的行为>>>
通过签订移位运算符是这样的:
You can implement the behavior of the unsigned right shift operator >>>
with the signed shift operators like this:
的值 N'GT;>> S
是 N
右移与零扩展s
位的位置。如果 N
为正,那么结果是一样的为n>> S
;如果 N
为负,其结果是等于前pression (N>&GT S)的+(2';< 〜S)
如果左侧操作数的类型的 INT 的,并且到EX pression (N&GT的结果;&GT S)+(2L<<〜S)
如果左侧操作数的类型的长的。增加的长期(2';<〜S)
或(2L<<〜S)
抵消了传播符号位。
The value of
n>>>s
isn
right-shifteds
bit positions with zero-extension. Ifn
is positive, then the result is the same as that ofn>>s
; ifn
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.
这篇关于PHP右移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!