Computer-bit operation (with Java for example)

the Test class {public 
	public static void main (String [] args) { 
		//. 1, left (<<) 
		after // 0000 0000 0000 0000 then left 0,000,000,000,000,101 2, 0 Low complement: // 
		// 0000 0000 0000 0000 in terms 0,000,000,000,010,100 is hexadecimal 10 20 
		System.out.println (<< 2. 5); // run result 20 

		// 2, right (>>) the high bit of the symbol bit 
		// 0000 0000 0000 0000 0000 0000 0000 0101 and two right, high bit 0: 
		// 0000 0000 0000 0000 0000 0000 0000 0001 
		System.out.println (>> 2. 5); // operation result is 1 

		// 3, no symbol right (>>>) high bit 0 
		// example, -5 to the terms of a binary: 0101 to 1011 invert plus 1 
		// 1,111,111,111,111,111 1,111,111,111,111,011 
		// we were to be shifted to the right three 5 -5 right shift by 3 bits and unsigned right shift 3: 
		System.out.println (>>. 5. 3); // result is 0 
		System.out.println (-5 >>. 3); // result is -1 
		System.out.println (-5 >>>. 3);// result is 536870911 

		// 4-bit and (&)
		// bits of: a first n-number of operation located on the second n-bit is 1 if the operand, then the result is also of n is 1, otherwise 0 
		System.out.println (&. 5 3); // results. 1 
		System.out.println (&. 1. 4); // result is 0 

		@ 5, or position (|) 
		of the n-// first operand of the second operand is located as long as the n-th bit is a 1, then the result is also of n is 1, otherwise 0 
		System.out.println (. 5 |. 3); // result 7 

		// 6, bit exclusive oR (^) 
		/ the first n / a number of operation located on the n-bit second operand contrary, it is also the result of n is 1, otherwise 0 
		 System.out.println (^. 5. 3); // results 6 

		// 7, the non-bit (~) 
		// operand bit n is 1, then the result of the n-th bit is 0, and vice versa. 
		System.out.println (~ 5); // result -6 
	} 
}

Guess you like

Origin www.cnblogs.com/linwenbin/p/10958889.html