开发者

implement this variable in java

Suppose code is given like this:

pattern_mask[pattern[i开发者_如何学JAVA]] &= ~(1UL << i);

What kind of type is this in Java? How do I implement this in Java?


Java does not have unsigned long, but 1L is a 64-bit signed long literal.

References

  • JLS 4.2.1 Integral Types and Values
    • For long, from -9223372036854775808 to 9223372036854775807, inclusive
  • JLS 3.10.1 Integer Literals
    • An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int. The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

On masking of count operand

The shift count is masked: only lower 5-bits for int shift, and only lower 6-bits for long shift.

The following snippet shows how due to this, shifting on 1 is different from shifting on 1L.

System.out.println(1 << 1); // prints "2"
System.out.println(1 << 33); // prints "2"
System.out.println(1L << 33); // prints "8589934592"
System.out.println(1L << 65); // prints "2"

Related questions

  • What’s the reason high-level languages like C#/Java mask the bit shift count operand?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜