Basic data type details

Data types in Java are divided into eight categories, 7 basic data types, and a reference type. The Insert picture description here
computer uses the two-level original code's complement to represent the number of symbols, that is, 1B (byte, byte) = 8 bit,
so just Have

byte 1 byte is eight bits maximum 127 minimum -128

1. Why is 8-bit not 255 but 127?
Answer: The highest bit of the number of signs is the service number. Bit 0 means positive number 1 means negative number
2. We all know that the range of numbers that a Byte can express is [-128,127], so how does -128 come from?
Answer:
Positive number:
original code== inverse code== complement code
ie: original: 0000 0001 ----- reverse: 0000 0001 ------ complement: 0000 0001

negative number:

Inverse code == the non-sign bit of the original code is inverted
Complement code == Inverse code +1

That is, the original: 1000 0001 ------ reverse: 1111 1110 ------ supplement: 1111 1111

The original code, the complement code, and the complement code can all represent the same number. The
computer uses the complement code to store a number.

So the number corresponding to the data type is easy to remember

byte: The
byte data type is 8-bit , signed, and an integer represented by two's complement; the
minimum value is -128 (-2^7); the
maximum value is 127 (2^7-1);

short:

The short data type is a 16-bit , signed integer expressed in twos complement. The
minimum value is -32768 (-2^15); the
maximum value is 32767 (2^15-1);

int:

The int data type is a 32-bit signed integer expressed in twos complement; the
minimum value is -2,147,483,648 (-2^31); the
maximum value is 2,147,483,647 (2^31-1);

long:

The long data type is a 64-bit signed integer represented by twos complement; the
minimum value is -9,223,372,036,854,775,808 (-2^63); the
maximum value is 9,223,372,036,854,775,807 (2^63 -1);

float:

The float data type is a single-precision, 32-bit , floating-point number conforming to the IEEE 754 standard;
float can save memory space when storing large floating-point arrays;

double:

The double data type is a double-precision, 64-bit , floating-point number conforming to the IEEE 754 standard;

Question : Why is the same 32-bit 64-bit double, float larger than int...

Answer : float is not simply stored like 101010, it divides 4 bytes into
sign bit, exponent bit, mantissa bit such as 1.123123*10^35;
3 parts are fixed, because there are exponents, the storage range is of course larger than int Big. The larger the value, the less precise

boolean:

The boolean data type represents one bit of information;
there are only two values: true and false;

char:

The char type is a single 16-bit Unicode character ; the
minimum value is \u0000 (ie 0); the
maximum value is \uffff (ie 65,535); the
char data type can store any character;

C++7 basic data types
Type keyword placeholder
Boolean bool 1 bit
Character char 1 byte
Integer int 4 bytes
Floating point float 4 bytes
Double floating point double 8 bytes
Untyped void
wide character Type wchar_t 2 or 4 bytes

The data type modifier
signed has a sign bit (in fact, the default type is this so it can be omitted) signed

unsigned unsigned (1 byte 8-bit binary highest bit is the sign bit and the sign bit is removed) For example: the value range of char is -127 to 128, the sign bit is removed, the value range of unsigned char is 0 to 255

short shortened byte short int 2 bytes
long increased byte long int 8 bytes

Guess you like

Origin blog.csdn.net/qq_35189120/article/details/84147593