当前位置:网站首页>实例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))
运行结果:
边栏推荐
- BM7 list entry in central
- August 10, 2022: Building Web Applications for Beginners with ASP.NET Core -- Creating Web UIs with ASP.NET Core
- 12 Recurrent Neural Network RNN2 of Deep Learning
- The perfect alternative to domestic Gravatar avatars Cravatar
- MySQL:MySQL的集群——主从复制的原理和配置
- 金山云CEO王育林离职:正值冲刺港股之际 雷军曾送金砖
- DC-7靶场下载及渗透实战详细过程(DC靶场系列)
- ASCII, Unicode and UTF-8
- GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
- 特别的三杯鸡
猜你喜欢
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
高通平台开发系列讲解(应用篇)QCMAP应用框架介绍
企业云存储日常运行维护实践经验分享
ArcGIS应用基础知识
Detailed installation steps and environment configuration of geemap
【640. Solving Equations】
mmpose关键点(一):评价指标(PCK,OKS,mAP)
解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线
爬虫request.get()出现错误
Pro-test is effective | A method to deal with missing features of risk control data
随机推荐
3598. Binary tree traversal (Huazhong University of Science and Technology exam questions)
pytorch tear CNN
unusual understanding
OneNote 教程,如何在 OneNote 中整理笔记本?
配电网络扩展规划:考虑使用概率性能源生产和消费概况的决策(Matlab代码实现)
美味的佳肴
win系统下pytorch深度学习环境安装
Extended Chinese Remainder Theorem
What would happen if disconnecting during the process of TCP connection?
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
The perfect alternative to domestic Gravatar avatars Cravatar
如何成为一名正义黑客?你应该学习什么?
Distribution Network Expansion Planning: Consider Decisions Using Probabilistic Energy Production and Consumption Profiles (Matlab Code Implementation)
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
ArcGIS应用基础知识
带着昇腾去旅行:一日看尽金陵城里的AI胜景
诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
OneNote tutorial, how to organize notebooks in OneNote?
ArcGIS中的坐标系统和投影变换
高学历毕业生,该学单片机还是plc?