0

When declaring the number 0xFFFFFFFF (4294967295) as a long, java will set the variable to the number -1.

public static final long Bits32 = 0xFFFFFFFF; //Bits32 = -1

I assume that java initially converts the hexadecimal to an integer and then converts this to the long variable. The obvious work around would to set Bits32 to the number 4294967295 instead. However this doesn't seem like a neat solution to me.

Dose anyone know how I would be able to declare a long to this number without having to manually convert the hexadecimal?

Cheers, Chris.

Chris192
  • 43
  • 5

1 Answers1

0

Define as a Hex Long:

    long Bits32 = 0xFFFFFFFFL; //Bits32 = -1
    System.out.println(Bits32);
    System.out.println(Long.toHexString(Bits32));

Note the L at the end of the 0xFFFFFFFF

The output is

4294967295
ffffffff

Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64