码迷,mamicode.com
首页 > 编程语言 > 详细

java无符号移位(>>>)和有符号移位(>>)

时间:2015-01-15 23:38:43      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

java中>>(<<)表示有符号的移位。<<<(>>>)表示无符号移位

如:

int num = 22;

二进制是0001 0110, num>>>1,右移一位变成0000 1011(11)

int num = -22

二进制用补码表示:1110 1001, num >>>1无符号右移一位: 0111 0100

>>向右移动后,最左边用符号位替补。>>>向右移动后最左边用0替补

1 public class Test {    
2     public static void main(String args[]){
3         int num = -22;
4         int temp = num >>> 1;
5         System.out.println("temp = " + temp);
6         temp = num >> 1;
7         System.out.print("temp = " + temp);
8     }
9 }

output:

temp = 2147483637
temp = -11

 

java无符号移位(>>>)和有符号移位(>>)

标签:

原文地址:http://www.cnblogs.com/luckygxf/p/4227449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!