r/javahelp • • Dec 03 '14

Gangnam Style and 32bit Integer

Yes, YouTube video view count is limited to a 32 bit Integer. Gangnam Style has more so YouTube will fix it. Channel views do not have this problem.

I have a question. Is there 64bit integers available to programmers using 64bit architecture? If not, why not?

Thanks.

0 Upvotes

7 comments sorted by

4

u/IXENAI Dec 03 '14

Is there 64bit integers available to programmers using 64bit architecture?

Of course; you can use 64-bit integers on a 32-bit architecture as well. Java defines an int as a 32-bit signed two's complement integer, and a long as a 64-bit signed two's complement integer regardless of the host platform's underlying architecture.

1

u/uf82 Dec 04 '14

I get the impression "long l = 19009" would be stored as an int because it's not long enough.

"long l =19009L"

would be 64bit. That's the impression I got.

1

u/IXENAI Dec 04 '14

You're partially correct. 19009 is an int literal; i.e. 32-bits. Once you store it in a long, however, it is cast to a (64-bit) long. Just like when you say double d = 3; d still holds a double (3.0) even though 3 is an int literal. The int literal is cast to a double during assignment.

1

u/uf82 Dec 03 '14

Thank you for your answers. I also went looking for some documentation.

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

2

u/brunokim Dec 03 '14 edited Dec 03 '14

In Java, numbers have fixed size, regardless of architecture.

  • byte is 8-bit (duh)

  • short is 16-bit

  • int is 32-bit

  • long is 64-bit

The architecture will influence the performance of your code. If you do CPU-intensive operations in longs, you should expect a 2x speedup for switching from a 32-bit to a 64-bit architecture.

1

u/RhoOfFeh Dec 03 '14

Of course. The long primitive type is a 64 bit signed integer (unsigned available with new JDKs)

1

u/tec5c Dec 03 '14

Yes.

In Java the primitive long is a 64 bit integer.

In a 32 bit processor a 64 bit integer is stored as two 32 bit words.