当前位置:网站首页>实例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))运行结果:
边栏推荐
猜你喜欢

This visual tool artifact is more intuitive and easy to use!love so much

uni-app微信小程序——下拉多选框

这款可视化工具神器,更直观易用!太爱了

链表中的节点每k个一组翻转

Shell 编程--Sed

Merge k sorted linked lists

shell脚本

2021IDEA创建web工程

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

测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
随机推荐
ThreadLocal comprehensive analysis (1)
常用代码扩展点设计方式
Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
诺诚健华通过注册:施一公家族身价15亿 高瓴浮亏5亿港元
web项目访问引用jar内部的静态资源
谁是边缘计算服务的采购者?是这六个关键角色
GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
Black cats take you learn Makefile article 13: a Makefile collection compile problem
STL-stack
August 10, 2022: Building Web Applications for Beginners with ASP.NET Core -- Creating Web UIs with ASP.NET Core
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
学会开会|成为有连接感组织的重要技能
美味的石井饭
RecyclerView上下滑动时,不调用onBindViewHolder 导致列表的item不刷新
元宇宙社交应用,靠什么吸引用户「为爱发电」?
如何成为一名正义黑客?你应该学习什么?
Conditional Statements of Shell Programming (2)
The Thread State,
QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍