当前位置:网站首页>运算符<< >>傻瓜式测试用例
运算符<< >>傻瓜式测试用例
2022-07-04 06:18:00 【东西方集大成者】
千万要牢记: 左边是被操作数,右边是移动位数(这对左移符和右移符来说都是一样的)
public class Test {
// 从极限出发,傻瓜式测试
public static void main(String[] args) {
/*** 左移测试 ***/
// 被操作数 左移箭头 左移位数 二进制 十进制
System.out.println(1 << 0); // 1 向左移0位, 1 = 1
System.out.println(1 << 1); // 1 向左移1位, 10 = 2
System.out.println(1 << 2); // 1 向左移2位, 100 = 4
System.out.println(1 << 3); // 1 向左移3位, 1000 = 8
System.out.println(1 << 4); // 1 向左移4位,10000 = 16
System.out.println(2 << 1); // 2 向左移1位,10 变 100 即 4
System.out.println(2 << 2); // 2 向左移2位,10 变 1000 即 8
System.out.println(2 << 3); // 2 向左移3位,10 变 10000 即 16
System.out.println(2 << 4); // 2 向左移4位,10 变 100000 即 32
System.out.println(3 << 1); // 3 向左移1位,11 变 110 即 6
System.out.println(3 << 2); // 3 向左移2位,11 变 1100 即 12
System.out.println(3 << 3); // 3 向左移3位,11 变 11000 即 24
System.out.println(3 << 4); // 3 向左移4位,11 变 110000 即 48
/*** 右移测试 ***/
// 被操作数 右移箭头 右移位数 二进制 十进制
System.out.println(1 >> 0); // 1 向右移0位, 1 = 1
System.out.println(1 >> 1); // 1 向右移1位, 0 = 0
System.out.println(1 >> 2); // 1 向右移2位, 0 = 0
System.out.println(1 >> 3); // 1 向右移3位, 0 = 0
System.out.println(1 >> 4); // 1 向右移4位, 0 = 0
System.out.println(2 >> 0); // 2 向右移1位,10 变 10 即 2
System.out.println(2 >> 1); // 2 向右移1位,10 变 01 即 1
System.out.println(2 >> 2); // 2 向右移2位,10 变 00 即 0
System.out.println(2 >> 3); // 2 向右移3位,10 变 00 即 0
System.out.println(2 >> 4); // 2 向右移4位,10 变 00 即 0
System.out.println(3 >> 1); // 3 向右移1位,11 变 01 即 1
System.out.println(3 >> 2); // 3 向右移2位,11 变 00 即 0
System.out.println(3 >> 3); // 3 向右移3位,11 变 00 即 0
System.out.println(3 >> 4); // 3 向右移4位,11 变 00 即 0
}
}
边栏推荐
- Notes and notes
- C réaliser des jeux de serpents gourmands
- Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
- [untitled]
- How to implement lazy loading in El select (with search function)
- Install pytoch geometric
- SQL injection SQL lab 11~22
- How to solve the component conflicts caused by scrollbars in GridView
- R统计绘图-随机森林分类分析及物种丰度差异检验组合图
- Reading notes of Clickhouse principle analysis and Application Practice (4)
猜你喜欢
Webrtc quickly set up video call and video conference
Leetcode question brushing record | 206_ Reverse linked list
[untitled]
C réaliser des jeux de serpents gourmands
C语言练习题(递归)
Practical gadget instructions
Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
Yiwen unlocks Huawei's new cloud skills - the whole process of aiot development [device access - ESP end-to-side data collection [mqtt]- real time data analysis] (step-by-step screenshot is more detai
AWT common components, FileDialog file selection box
报错cvc-complex-type.2.4.a: 发现了以元素 ‘base-extension‘ 开头的无效内容。应以 ‘{layoutlib}‘ 之一开头。
随机推荐
JS get the attribute values nested in the object
如何避免 JVM 内存泄漏?
el-select如何实现懒加载(带搜索功能)
How to avoid JVM memory leakage?
JSON web token -- comparison between JWT and traditional session login authentication
C语言练习题(递归)
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
Take you to quickly learn how to use qsort and simulate qsort
JS execution mechanism
Kubernets first meeting
How to implement lazy loading in El select (with search function)
MySQL installation and configuration
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
SQL join, left join, right join usage
Webrtc quickly set up video call and video conference
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
My NVIDIA developer journey - optimizing graphics card performance
C实现贪吃蛇小游戏
Detectron: train your own data set -- convert your own data format to coco format