当前位置:网站首页>实例054:位取反、位移动
实例054:位取反、位移动
2022-08-10 22:20:00 【懒笑翻】
题目:取一个整数a从右端开始的4〜7位。
程序分析:可以这样考虑: (1)先使a右移4位。 (2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4) (3)将上面二者进行&运算。
代码:
a=int(input('输入一个数字: '))
b=0 # 0
b=~b # 1
b=b<<4 # 10000
b=~b # 1111
c=a>>4
d=c&b
print('a:',bin(a))
print('b:',bin(b))
print('c:',bin(c))
print('d:',bin(d))
运行结果:
边栏推荐
- MySQL Advanced Commands
- Spark基础【RDD转换算子】
- 2022年8月的10篇论文推荐
- Introduction to the use of counter instructions in Rockwell AB PLC RSLogix5000
- LeetCode Daily Question (1573. Number of Ways to Split a String)
- H3C S5130 IRF做堆叠
- BM13判断一个链表是否为回文结构
- DC-8靶场下载及渗透实战详细过程(DC靶场系列)
- Glide缓存核心原理详解
- Extended Chinese Remainder Theorem
猜你喜欢
Introduction to the use of counter instructions in Rockwell AB PLC RSLogix5000
RK3399 platform development series explanation (kernel-driven peripherals) 6.35, IAM20680 gyroscope introduction
12 Recurrent Neural Network RNN2 of Deep Learning
leetcode:355. 设计推特
68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
云服务器基于 SSH 协议实现免密登录
ArcGIS应用基础知识
68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
Glide监听Activity生命周期源码分析
随机推荐
CIKM2022 | 基于双向Transformers对比学习的序列推荐
带着昇腾去旅行:一日看尽金陵城里的AI胜景
Common interview questions for APP UI automation testing, maybe useful~
亲测有效|处理风控数据特征缺失的一种方法
Shell 编程--Sed
这款可视化工具神器,更直观易用!太爱了
Fatal error: cstring: No such file or directory
Self-organization is a two-way journey between managers and members
What is Jmeter? What are the principle steps used by Jmeter?
How does the Weiluntong touch screen display the current value of abnormal data while alarming?
GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
CFdiv2-Beautiful Mirrors-(期望)
字节跳动原来这么容易就能进去...
JS中使用正则表达式g模式和非g模式的区别
What are the concepts, purposes, processes, and testing methods of interface testing?
计算需要的MIPI lane数目
ASCII, Unicode and UTF-8
如何成为一名正义黑客?你应该学习什么?
LeetCode Daily Question (1573. Number of Ways to Split a String)
LeetCode Daily 2 Questions 01: Reverse Strings (both 1200) Method: Double Pointer