Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will an int be 32bit and a long 64bit regardless of whether the system is 32 or 64 bit?

In java, is an int guaranteed to always be of 32bit size and a long of 64bit size regardless of whether the architecture is 32 or 64 bit?

like image 745
Alex Florescu Avatar asked Aug 02 '13 13:08

Alex Florescu


People also ask

What is the difference between Int32 and int64/long?

Asker knows that int is 32 bit and long is 64 bit. – David Heffernan Mar 12, 2014 at 22:57 Add a comment | 4 Answers 4 ActiveOldestVotes 29 Don't you worry about that. The longvalue will be stored in 2 memory addresses. Int64/longwill always be 64bit, and Int32/intwill always be 32bit.

Why can't we make a 32 bit int into a 64 bit int?

If a plain int is adjusted to 64 bits, the constraint that sizeof (int) <= sizeof (long) would force long to be at least 64 bits and from there there's an intrinsic gap in sizes. Since long or a plain int usually are used as a 32 bit integer and neither of them could now, we only have one more data type that could, short.

What is the difference between 32 bit and 64 bit operating system?

A 32-bit system can access 2 32 different memory addresses, i.e 4 GB of RAM or physical memory ideally, it can access more than 4 GB of RAM also. A 64-bit system can access 2 64 different memory addresses, i.e actually 18-Quintillion bytes of RAM. In short, any amount of memory greater than 4 GB can be easily handled by it.

Is'int'16-bit or 32-bit?

d 32-bit microcomputers define "char" as 8 bits, "short" as 16 bits, and "long" as 32 bits. The only difference among them is whether "int" is 16 bits or 32. While a 32-bit or larger CPU could use "int" as a 32-bit type, leaving "long" available as a 64-bit type, there is a substantial corpus of code which expects that "long" will be 32 bits.


2 Answers

Java is platform independent. So int is 32-bits, and long is 64-bit.

like image 158
jh314 Avatar answered Oct 13 '22 09:10

jh314


int in Java is always 32-bit. No matter the OS type/architecture/whatever.

like image 25
Konstantin Yovkov Avatar answered Oct 13 '22 10:10

Konstantin Yovkov