+ 2

How is it possible for int to store 6 numbers?

I have seen on net that int can only store 4 bytes but I have tried it practically and it stored 6 numbered digit also,Why does this happen?

22nd Mar 2018, 1:56 PM
divyam sureka
divyam sureka - avatar
4 ответов
+ 5
Your concrete example could be stored in long (or java.lang.Long if this is necessary). If at any point you need bigger numbers, you can try java.math.BigInteger (if integer), or java.math.BigDecimal (if decimal)
22nd Mar 2018, 2:12 PM
Baraa AB
Baraa AB - avatar
+ 4
You're using the words "bytes" and "numbers" as if they're the same thing, which they aren't. Bytes is referring to the memory storage unit, which is quite different. There are 8 bits in a byte, and in this case you're working with 4 bytes, which gives you 32 bits to make up the numbers you're wanting. In regards to numbers, 32 bits gives you room to do a lot (billions?). Anyways, your best means of understanding this is to better understand memory and how its units work (and why). If nothing more, I'm sure there are millions of charts in the online world that has this mapped out.
22nd Mar 2018, 2:06 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
1byte=8bits 4bytes=32bits Store in binary can have 32 "0"or "1" one bit mark + - 32-1=31bits int: -2^31~0~2^31-1
23rd Mar 2018, 6:05 PM
gtbandc
gtbandc - avatar