Ary
For integer, there are four representations:
Binary: 0, 1, 2 into 1 full begin with 0b or 0B.
Decimal: 0-9, 1 full 10 into
octal: 0-7, 1. Expresses its full 8 into a digital 0 at the beginning.
Hex: 0-9 and AF, 1. Expresses its full hexadecimal with 0x or 0X. AF here are case insensitive.
All numbers are present in binary form at the bottom of the computer.
The computer saves all the integers in the form of complement.
Complement positive number of the same original code thereto; negative complement is added to the last bit 1 in its inverted.
Original code: directly into a binary value.
Inverted: Is the original code Bitwise, but the most significant bit (sign bit) remain unchanged.
Java is the default type int integer constants, when an integer defining binary, which is the sign bit position 32; when the type is long, the 64-bit binary default account, is the sign bit 64
byte range: -128 to 127
The basic binary conversion
Huzhuan Decimal Binary
Decimal to Binary conversion take the remainder divided by 2
Binary Coded Decimal multiplied by powers of 2
15 = 1 * 2^0 + 1 * 2^1 + 1 * 2^2 + 1 * 2^3
Similar methods can make the following system conversion
binary conversion between octal
binary hex conversion between
decimal conversion between octal
decimal hexadecimal system conversion
Arithmetic Operators
note:
If a negative modulo the modulus can be negligible negative sign, such as: 5 = 1% -2. But was negative modulus is another matter.
For the division sign "/", in addition to its integer and fractional addition there is a difference: when doing integer division between, leaving only the integer part and the fractional part is discarded. For example: int x = 3510; x = x / 1000 * 1000; the results of x is?
"+" Except string adding functions, can convert non-string to string, for example: System.out.println ( "5 + 5 = " + 5 + 5); // print result Is?
Assignment Operators
Sign: =
extended assignment operator: + =, - =, * =, / =,% =
Comparison operators (relational operator)
Note 1: The results of the comparison operators are boolean type, that is either true, or is false.
Note 2: The comparison operator "==" can not be mistakenly written as "=."
Logical Operators
Logical operators for connecting Boolean expressions, written in Java can not 3 <x <6, should be written as x> 3 && x <6.
The difference between "&" and "&&": the
single &, whether true or false to the left and right have carried out operations;
dual &, if the left is true, the right to participate in operation, if the left is false, then the right not to participate in operations.
And the difference between "||" in the same way, when double or left is really the right not to participate in operations.
XOR (^) and or (|) of the difference is that: For ^, when left and right are true, the result is false.
Bitwise Operators
Bit operation is carried out directly on the binary arithmetic
Ternary operator
? :( format conditional expression) expression 1: Expression 2;
if the condition is true, the result of arithmetic expressions is 1;
if the condition is false, the result of the operation is the expression 2;
Package com.uncleyong; public class TestOperator { public static void main (String [] args) { // modulo int R & lt = 10%. 3 ; System.out.println (R & lt); // . 1 // increment int I = 10 ; // i ++: first take the value of i, in operation (i = i +. 1) int J = i ++ ; System.out.println (J); System.out.println (i); int m = 100 ; // + + m: first calculation (m = m + 1), the value of int n-++ = m; System.out.println (n-); System.out.println (m); // +: string concatenation String STR = "ABC" ; String str2 = "DEF" ; String Str3 = + STR str2; // abcdef System.out.println (Str3); // if a negative modulo the modulus can be negligible negative sign System.out.println (10% -3); // . 1 // If the mode number is negative, its absolute value to be taken modulo operation, together with a negative sign result System.out.println (-10%. 3); // -1 System.out.println ( -10% -3); // -1 // do integer division between when, leaving only the integer portion and the fractional part is discarded int X = 3510 ; XX = / 1000 * 1000 ; System.out.println (X); // 3000 // + except string adding functions, can convert non-string into a string String str4 = ". 1" ; System.out.println (str4 + 100) ; // 1100 // logical operator int a = 10 ; int B = 20 is ; // &: the operator, if and only if both sides are true, the result expression is to true System.out.println (a >. 5 & B <30); // to true System.out.println (A> 15 B & <30); // to false System.out.println (A> B. 5 & <20 is); // to false // | : oR operator, if and only if both sides are false, the result of the expression is false System.out.println (A>. 5 | B <30); // to true System.out.println (A> 15 | B <. 3); // to false System.out.println (A>. 5 | B <20 is) ; // to true // ^: exclusive-oR operator, if and only if the result of the expression is not the same on both sides to true, otherwise to false System.out.println (a> B ^. 5 <30); // to false the System .out.println (A> B ^ 15 <. 3); // to false System.out.println (A> B ^. 5 <20 is); // to true // :!. negation operator System.out.println ( ! (a>. 5)); // to false // shorting logical operators: &&, || short circuit if the previous expression may determine the logical operators have the entire expression,. @Determined value of the expression is no longer shorted behind the operator System.out.println (A> 15 && (10/0 ==. 1)); // to false // bitwise int C =. 3; // 0000 0011 // left-shift operator System.out.println (C << 2); // 0000 1100 is -> 12 is. 3 * (2 * 2) = 12 is // right shift operator System.out.println (c >> 2 ); // 00000000--> 03 / (2 * 2) = 0; // unsigned right shift operator int D = -1 ; System.out.println (D >>. 1); // -1 the System .out.println (D >>>. 1); // 2147483647 // & Bitwise operators / * 0000 0010 * * 0000 & 0011 * ___________ * 0000 0010 * / System.out.println ( 2 &. 3); // 2 // ternary operator ? String e = d> 3 " d> 3": "d < . 3 = " ; System.out.println (E); // D <=. 3 // not compile because: the sides must be an expression, and must be compatible with the type of expression // D> the System. 3?. Out.println ( "A"): System.out.println ( "B"); String RES = D>. 3 ">. 3":? "<=. 3" ; } }
This article reprinted from full-stack test notes https://www.cnblogs.com/UncleYong/p/9729156.html Thanks for sharing the power of God.