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-9223372036854775808to9223372036854775807, inclusive
- For
- JLS 3.10.1 Integer Literals
- An integer literal is of type
longif it is suffixed with an ASCII letterLorl(ell); otherwise it is of typeint. The suffixLis preferred, because the letterl(ell) is often hard to distinguish from the digit1(one).
- An integer literal is of type
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?
加载中,请稍侯......
精彩评论