当前位置:网站首页>实例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))运行结果:
边栏推荐
- Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?
- ASCII, Unicode and UTF-8
- Splunk中解决数据质量问题常见日期格式化
- Common interview questions for APP UI automation testing, maybe useful~
- 【开源教程5】疯壳·开源编队无人机-飞控固件烧写
- BM7 list entry in central
- y93.第六章 微服务、服务网格及Envoy实战 -- Envoy配置(四)
- B站数据分析岗实习生面试记录
- 68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
- Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
猜你喜欢

字节跳动原来这么容易就能进去...

Translating scientific and technological papers, how to translate from Russian to Chinese

12 Recurrent Neural Network RNN2 of Deep Learning

Nodes in the linked list are flipped in groups of k

诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元

unusual understanding

How to be a Righteous Hacker?What should you study?

金山云CEO王育林离职:正值冲刺港股之际 雷军曾送金砖

DC-8靶场下载及渗透实战详细过程(DC靶场系列)

【640. 求解方程】
随机推荐
LeetCode每日两题01:反转字符串 (均1200道)方法:双指针
port forwarding
This visual tool artifact is more intuitive and easy to use!love so much
IM 即时通讯开发如何设计图片文件的服务端存储架构
“数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
2022年8月的10篇论文推荐
谁是边缘计算服务的采购者?是这六个关键角色
自学软件测试不知道该如何学起,【软件测试技能图谱|自学测试路线图】
Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
CFdiv2-Common Number-(奇偶数二分+规律)
leetcode:355. 设计推特
链表中的节点每k个一组翻转
What would happen if disconnecting during the process of TCP connection?
阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
高通平台开发系列讲解(应用篇)QCMAP应用框架介绍
String类的常用方法
make & cmake
y93.第六章 微服务、服务网格及Envoy实战 -- Envoy配置(四)
How does the Weiluntong touch screen display the current value of abnormal data while alarming?
mmpose关键点(一):评价指标(PCK,OKS,mAP)