互联网技术 / 互联网资讯 · 2023年12月18日

Python实例练习:云计算开发中取整数a右端开始的4-7位

题目:取一个整数a从右端开始的4-7位。

程序分析:可以这样考虑:

(1)先使a右移4位。

(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4)

(3)将上面二者进行&aMp;运算。

程序源代码:

云计算开发:Python练习实例-取整数a从右端开始的4-7位

以上实例输出结果为:

云计算开发:Python练习实例-取整数a从右端开始的4-7位

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册