Reputation: 59178
I tried the following:
public static final long DEVICE_ID_UNKNOWN = 0xFFFFFFFFFFFFFFFF;
but it causes
The literal 0xFFFFFFFFFFFFFFFF of type int is out of range
Upvotes: 4
Views: 5125
Reputation: 13083
You may use either of the following:
public static final long DEVICE_ID_UNKNOWN = 0xFFFFFFFFFFFFFFFFL;
or
public static final long DEVICE_ID_UNKNOWN = ~0L;
or
public static final long DEVICE_ID_UNKNOWN = -1L;
Upvotes: 7
Reputation: 533530
Yet another way to get all 1s
public static final long DEVICE_ID_UNKNOWN = ~0L;
Upvotes: 3
Reputation: 11543
You need to specify the type of the number if it can not be represented as an int. A long is a L or l (lowercase). I prefer uppercase as lowercase is easy to mistake for 1 (one).
public static final long DEVICE_ID_UNKNOWN = 0xFFFFFFFFFFFFFFFFL;
Or, you can just set the value to -1, but that might not be as clear in communicating the meaning "all bits 1".
Upvotes: 7
Reputation: 11257
public static final long DEVICE_ID_UNKNOWN = 0xFFFF_FFFF_FFFF_FFFFL;
Usefull reference http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Upvotes: 1
Reputation: 143099
Sorry, I'm not the java
guy, but wouldn't -1
do?
Upvotes: 1
Reputation: 66263
Use 0xFFFFFFFFFFFFFFFFl
and be fine.
Another way would be to use simply -1
because this value also has all bits set. See http://en.wikipedia.org/wiki/Two%27s_complement for details.
Upvotes: 8
Reputation: 38345
Use public static final long DEVICE_ID_UNKNOWN = 0xFFFFFFFFFFFFFFFFL;
instead to signify that it's a long value, not an int value.
Upvotes: 1