SHORT type variable in Java

xiaoxiao2021-03-05  24

First come and see the basic types in Java, as follows:

Primitive typeSizeMinimumMaximumWrapper typeboolean --- Booleanchar16-bitUnicode 0Unicode 216- 1Characterbyte 8-bit-128 127Byteshort16-bit-215 215-1Shortint32-bit-231 231-1Integerlong64-bit-263 263-1Longfloat32-bitIEEE754IEEE754Floatdouble64-bit IEEE754IEEE754Doublevoid- --Void

Java's basic type storage length is fixed, not due to the difference in the machine, thus making Java have good portability.

Recently, when you do a project, you need to store 16 long binary numbers in a variable. You can see that the Short type is in need.

However, since the number type in Java is a symbol, the first bit of the SHORT type is used to represent the symbol, and the actual storage length is only 15.

That is, -7FFF- 7FFF. What should I do if the number to store 7FFF- FFFF? Only the change algorithm is adopted. We can use -7FFF - 0001 to store numbers greater than 7FFF. The conversion formula is - (ffff-x) -1. Because of the symbol, 0000 and -0000 are equal, so there is one number than the no sign number, so we must reduce 1 in the formula. Due to this problem, we cannot store 8000 with this method.

This method can basically meet our needs, if there is special needs, if you want to store 8000, then there is only other ways.

转载请注明原文地址:https://www.9cbs.com/read-36962.html

New Post(0)