Java如何使用左移“ < <”运算符?
有符号左移运算符<<将一个位模式左移。该运算符使用两个操作数进行操作,左操作数要移位,右操作数告诉要移位多少位置。
0010使用<<运算符2的位置移动位图将产生1000位图。带符号的左移运算符产生的结果等于将数字乘以2,这会使数字的值加倍。
package org.nhooo.example.fundamental;
public class SignedLeftShiftOperator {
public static void main(String[] args) {
int number = 2;
System.out.println("number = " + number);
System.out.println("binary = " + Integer.toBinaryString(number));
int shiftedLeft = number << 2;
System.out.println("shiftedLeft = " + shiftedLeft);
System.out.println("binary = " + Integer.toBinaryString(shiftedLeft));
}
}代码段的结果:
number = 2 binary = 10 shiftedLeft = 8 binary = 1000
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短