tags:

views:

94

answers:

1

Suppose code is given like this:

pattern_mask[pattern[i]] &= ~(1UL << i);

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

+3  A: 

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

polygenelubricants