`
futeng
  • 浏览: 260999 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
Java 位运算、移位运算示例 java, 位运算, 移位运算
package demo.java.core.base;
/**
 * @author code@futeng.org
 * @date 2012-11-12下午9:06:46
 */
public class BinaryShifts {
	public static void main(String[] args) {

		/*位运算*/
		System.out.println("3 & -3 = "+(3&-3));  // 与
		System.out.println("2 |  2 = "+(2|-2));  // 或
		System.out.println("  ~ -2 = "+(~-2));   // 取反,非
		
		/*移位运算*/
		System.out.println("3 >> 2 = "+(3>>2));  // 算术右移
		System.out.println("-4<< 2 = "+(-4<<2)); // 算术左移
		System.out.println("-2>>>2 = "+(-2>>>2));// 逻辑右移
	}
}
Global site tag (gtag.js) - Google Analytics