Anon
Anon

Reputation: 37

Data Type for Hexadecimal in Java

long[] RC1 = { 0x0000000000000000, 0x13198a2e03707344, 0xa4093822299f31d0, 0x082efa98ec4e6c89, 0x452821e638d01377, 0xbe5466cf34e90c6c, 0x7ef84f78fd955cb1, 0x85840851f1ac43aa, 0xc882d32f25323c54, 0x64a51195e0e3610d, 0xd3b5a399ca0c2399, 0xc0ac29b7c97c50dd };

This code is not supported in Java as it shows the value of hexadecimal is too large. I have changed the values to decimal but it is still large. Is there any other solution?

Upvotes: 2

Views: 9876

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

You have to indicate those are long (and not int) constants. You can do so by adding a suffix of the letter l or L, like

long[] RC1 = { 0x0000000000000000L, 0x13198a2e03707344L,
            0xa4093822299f31d0L, 0x082efa98ec4e6c89L, 0x452821e638d01377L,
            0xbe5466cf34e90c6cL, 0x7ef84f78fd955cb1L, 0x85840851f1ac43aaL,
            0xc882d32f25323c54L, 0x64a51195e0e3610dL, 0xd3b5a399ca0c2399L,
            0xc0ac29b7c97c50ddL };

From JLS-3.10.1

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 (§4.2.1).

The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

Upvotes: 6

Related Questions