Symbolic data representation: original code, anti-code, complement
When the computer is operating, it is calculated by using the binary complement of the data corresponding
Example: Using the original code, anti-code, complement to represent +7 and 7 respectively
First, convert to binary: 00000111
Original code: Symbol bit + value bit, where the highest 0 is a positive number, 1 means negative
+7:0 000111
-7:1 000111
Anti-code: The inverse code of positive number is the same as the original code, negative number of the inverse code is to its original code bitwise negation, except the sign bit
+7:0 000111
-7:1 111000
Complement: The complement of positive is the same as the original code, the complement of negative number is on the basis of anti-code plus 1
+7:0 000111
-7:1 111001
Data type
The Java language is a strongly typed language that defines specific data types for each type of data, and allocates a different size of memory space in memory
Classification:
A: Basic Data type: 4 classes of 8
B: Reference data type: Class, interface, array.
Basic data types
A: integer consumption of bytes
BYTE 1
Short 2
int 4
Long 8
B: Floating point
Float 4
Double 8
C: Character
Char 2
D: Boolean
Boolean 1
Attention:
integers are type int by default, and floating-point numbers are double by default.
Long integers to be added L or L.
Single-precision floating-point numbers are added F or f.
Considerations for Using Variables:
A: Scope
B: Initialize Value
C: Multiple variables can be defined on the same line, but not recommended
Data type conversions:
(1) Boolean type does not participate in conversions
(2) Default conversion
A: From small to large
B:Byte,short,char--INT--long--float--double
C:Byte,short,char do not convert to each other, directly into the int type participates in the operation.
byte a=1;
int b=2;
BYTE C=a+b; Error
int d=a+b; That's right
(3) Forced conversion
A: from big to small
B: There may be a loss of precision, it is generally not recommended
byte a=1;
int b=2;
byte c= (Byte) (A+B); That's right
C: Format:
Target data type variable name = (target data type) (converted data);
(4) Study Questions and interview questions:
A: Are there any differences in the following two ways?
float f1 = 12.345f; It was originally a float type.
float F2 = (float) 12.345; Originally a double type, forced to convert to float type
B: Is there a problem with the program below, and if so, where?
BYTE B1 = 3;
byte b2 = 4;
BYTE B3 = b1 + b2; problems, type promotion B1 and B2 participation calculations are converted directly to int type,
byte B4 = 3 + 4; No problem, constants first calculate the results, and then see if in the byte range class, if there is no error
C: What is the result of the following operation?
byte B = (byte) 130;
130 exceeds the range of byte ( -128~127)
Because computer computing is done with binary complement, we first put 130 into binary: 10000010
The original code of the positive number of the reverse code is the same: the 10000010,int type of 130 is originally 32 bits, when intercepted as a byte type, 8 bits, the highest bit is 1
After that, the complement: 10000010 into the inverse code: 10000001, and then converted to the original code is: 11111110, the decimal value is 126
D: Character participation operation
is to find the value inside the ASCII
' A ' 97
' A ' 65
' 0 ' 48
System.out.println (' a '); Result A
System.out.println (' a ' + 1); Results 98
System.out.println ("Hello" + ' a ' + 1);//result helloa1, string data and other data do +, the result is a string type , where the + is the connector
System.out.println (' A ' +1+ "hello");//Result 98hello, first calculate + method, then concatenate string