1.1 Constants:
Basic data Type Constants
Character constants
The representation of an integer constant: a binary representation (binary, octal, decimal, hexadecimal)
In life: Decimal (0-9), Week (Seven decimal (0-6)), Time (12 binary (0-11), 24 binary (0-23))
Computers are binary to read the data in our lives.
Conversions between the binaries:
Decimal to binary: divides the decimal by 2 until the quotient is 0, and the remainder is connected from the bottom to the binary.
Ten---->1010
Binary to decimal: multiplies each bit of the binary by 2^n, N starts at 0, N adds one each time, and adds the result.
1001----"1*2^0 +0*2^1 +0*2^2+1*2^3 = 9
Binary transposition octal:
Way 1:2 binary---> Decimal---> Octal
Mode two: An octal equivalent of three binary for, will be binary three bit a split, calculated
010 100 101 = 245
Change binary to 16: (0-9) (A ()-f (15))
0000 1010 0101 = A5
1.2 Variables:
Java data types fall into two categories:
1. Basic data types
BYTE (byte) 8-bit (bit)
2. Reference data types
string literal.
How variables are declared:
1. Data type variable name
2. Data type variable name 1, variable name 2 ...
Data type:
Conversion of data types
1. Automatic type conversion
Small data Types---> Big data type Conversions
2. Forcing type conversions
Large data types----> Small data types.
Points to note in data type conversions:
1. Variables defined by short, byte, Char, when doing an operation,
Data types are automatically converted to int
2. Two different data types do operations, which are given depending on the large data type.
Two Operator. 1.1 Arithmetic operators: +,-, *,/,%1.2 self-increment: + +,--1.3 assignment operator: =, +=,-=,*=,/=1.4 relational operator: >,<,>=,<=,==,! =
Logical operators: &, | ,! ,&&, | |
Bitwise operators:
It is the calculation of the bits.
A bitwise operator is a decimal integer that can be computed by converting decimal into binary.
The binary consists of 0 and 1, so the result of the calculation is either 0 or 1
Symbols for 1.5-bit operators:
& (with): Both are 1 when I am one, the others are 0
| (OR): Both are 0 o'clock to 0, and the others are 1.
^ (XOR): The difference between the two is 1, the same as 0
~ (Inverse): 0 becomes 1, 1 becomes 0.
The representation of negative numbers: the highest bit of bits is 1, then this number is a negative.
1111-1111 1111-1111 1111-1111 1111-1111:-1
0000 0000 0000 0000 0000 0000 0000 0000:0
-2:1111-1111 1111-1111 1111-1111 1111-1110
-3:1111-1111 1111-1111 1111-1111 1111-1101
-4:1111-1111 1111-1111 1111-1111 1111-1100
-5:1111-1111 1111-1111 1111-1111 1111-1011
-6:1111-1111 1111-1111 1111-1111 1111-1010
-7:1111-1111 1111-1111 1111-1111 1111-1001
0000-0000 0000-0000 0000-0000 0000-0111 = 7
1111-1111 1111-1111 1111-1111 1111-1001
Rule: Negative number corresponding to the positive number-1, take the inverse
Negative number corresponding to the positive negation +1
Role: Data is encrypted
123456
0-100 A-Z
24845845957512317580960--->123456
1.6 Shift Operator: operation on Bits
1.6.1 >> Right Shift
1.6.2 << left Shift
1.6.3 >>> Unsigned Right shift
>> Right Shift
<< left Shift
>>> Unsigned Right Shift
Move right:
System.out.println (6>>1); --->3 6/2 2*1
System.out.println (6>>2); --->1 6/4 2*2
System.out.println (6>>3); --->0 6/8 2*3
System.out.println (6>>4);
System.out.println (9>>1); --->4 9/2 2*1
System.out.println (9>>2); --->2 9/4 2*2
System.out.println (9>>3); --->1 9/8 2*3
System.out.println (9>>4);//--->0 9/16
System.out.println ( -6>>1); -6/2-->-3
Rule: Shift the number of digits to the right by dividing by 2 how many times you need to move.
Move Left:
SYSTEM.OUT.PRINTLN ("-----This is the result of the left Shift----------");
System.out.println (6<<1); --->12 6*2 2*1
System.out.println (6<<2); --->24 6*4 2*2
System.out.println (6<<3); --->48 6*8 2*2*2
System.out.println (6<<4); ---->96 6*16 2*2*2*2
System.out.println ( -6<<2);//--->-24
Rule: How many digits to the left, multiply this number by 2 times.
>>> Unsigned Right Shift
System.out.println (6>>>1); 3
System.out.println (6>>>2); 1
System.out.println ( -6>>>2); 1073741822
Function: Increase the operation rate. Bit arithmetic is the fastest execution.
For example: Calculate 2*8 in the quickest way
2<<3 = = 2*8 = 16
Features: A number A and two the same number ^, the final result is still the original number A.
Java Basics Trivia