in-process
For integers, there are four ways to represent them:
Binary: 0,1, full 2 in 1. Start with 0b or 0 B.
Decimal: 0-9, full 10 in 1.
Octal: 0-7, full 8 in 1. denoted by the number 0.
Hex: 0-9 and A-f, full 16 in 1. Starts with a 0x or 0X representation. The a-f here are case insensitive.
all numbers exist in binary form at the bottom of the computer .
The computer saves all integers in the form of a complement .
the complement of a positive number is the same as its original code, and the complement of a negative number is the minus 1 of its inverse code.
Original code: Converts a value directly into a binary number .
Anti-code: is to the original code bitwise reversed, but the highest bit (sign bit) remains unchanged.
The Java integer constant is the int type by default, and when an integer is defined with a binary, its 32nd bit is the sign bit; when it is long, the binary default is 64 bits, and the 64th bit is the sign bit
Basic conversion of the binary
Decimal Binary Mutual Transfer
Decimal is converted to binary divided by 2 to take the remainder
Binary to decimal multiplied by power of 2
Binary octal in each other
Binary hexadecimal Mutual transfer
Decimal octal cross-transfer
Decimal hexadecimal cross-transfer
operatoroperator Classification
Arithmetic operators
Assignment operators
Comparison operators (relational operators)
logical operators
Bitwise operators
Ternary operators
Arithmetic Operators
//Take the moldintR = 10 3; System.out.println (R); //Self-incrementinti = 10; //i++: Take I value first, in operation (i = i + 1)intj = i++; System.out.println (j); J=i; System.out.println (j); intm = 100;//++m: First operation (m = m + 1), followed by valueintn = + +m; SYSTEM.OUT.PRINTLN (n); N=m; SYSTEM.OUT.PRINTLN (n); //+: string additionString str = "ABC"; String str2= "Def"; String STR3= str + str2;//abcdefSystem.out.println (STR3); //If you modulo negative numbers, you can ignore the modulus minusSYSTEM.OUT.PRINTLN (10-3);//1//if the number of the modulo is negative, the absolute value is first modulo and the result is prefixed with a minus signSYSTEM.OUT.PRINTLN (-10% 3);//-1System.out.println (-10%-3);//-1//When division is done between integers, only the integer part is left and the fractional part is discardedintx=3510; x= x/1000 * 1000; SYSTEM.OUT.PRINTLN (x); // the//+ Besides the function of string addition, it can convert non-string into stringString STR4 = "1"; System.out.println (STR4+ 100);//1100
if the negative number modulo, you can ignore the modulus minus , such as: 5%-2=1. But the modulus is a negative number is another matter.
For division Sign "/", its integers are distinguished from decimals except that the fractional part is preserved only when the integer is divided between integers . For example: int x=3510;x=x/1000*1000; The result of X is 3000.
"+" In addition to the string add function, can also convert non-string into a string. For example: System.out.println ("5+5=" +5+5); The print result is 5+5=55
Assignment Operators
Symbol: =
Extended Assignment operators: + =,-=, *=,/=,%=
//4000
comparison Operators
// comparison Operators // true
Note 1: The result of the comparison operator is Boolean, which is either true or false.
Note 2: The comparison operator "= =" cannot be mistakenly written as "=".
logical Operators
// logical Operators int a = ten; int B = 20;
Logical operators are used to concatenate Boolean expressions that cannot be written as 3<x<6 in Java and should be written in X>3 && x<6.
The difference between "&" and "&& "
Single &, both True and false on the left, the right side of the operation;
Double & If the left is true, the right side participates in the operation, if the left is false, then the right side does not participate in the operation.
and "| |" The difference is the same, dual or time, the left is true, the right does not participate in the operation.
XOR (^) with or (|) The difference is: for ^, when both left and right are true, the result is false.
//&: with operator, when and only if both sides are true, the result of an expression is trueSystem.out.println (A > 5 & B < 30);//trueSystem.out.println (A > & B < 30);//falseSystem.out.println (A > 5 & B < 20);//false//|: Or operator, when and only if both sides are false, the expression evaluates to FalseSystem.out.println (A > 5 | b < 30);//trueSystem.out.println (A > | b < 3);//falseSystem.out.println (A > 5 | b < 20);//true//^: Xor operator, False if and only if the result of both sides of the expression is not both trueSystem.out.println (A > 5 ^ b < 30);//falseSystem.out.println (A > ^ b < 3);//falseSystem.out.println (A > 5 ^ b < 20);//true//!: Take the inverse operator.SYSTEM.OUT.PRINTLN (! ( A > 5));//false//short-circuit logical operator: &&, | |. If the expression before the short-circuit logical operator is already able to determine the value of the entire expression,//The value of the expression behind the short-circuit operator is no longer judgedSystem.out.println (A > && (10/0 = = 1));//false
Bitwise Operators
Bitwise operations are performed directly on the binary
//Bitwise Operatorsintc = 3;//0000 0011//left shift operatorSystem.out.println (c << 2);//0000 1100 3 * (2*2) =//Right shift operatorSystem.out.println (c >> 2);//0000 0000-0 3/(2 * 2) = 0; //unsigned Right shift operatorintD =-1; System.out.println (d>> 1);//-1System.out.println (d >>> 1);//-1//& Bitwise Operators/** 0000 0010 * & 0000 0011 * ___________ * 0000 0010*/System.out.println (2 & 3);//2
Ternary operators
Format:
(conditional expression)? Expression 1: Expression 2;
If the condition is true, the result of the operation is an expression of 1;
If the condition is false, the result of the operation is an expression of 2;
// Ternary operators String e = d > 3? "D > 3": "D <= 3"// D <= 3 // compile cannot pass because: the two sides must be an expression and must be a type-compatible expression //D > 3? System.out.println ("a"): System.out.println ("B"); Boolean false : ">3";
Java basic Syntax----binary, operator