python3 循环位移动
python3 中 >> 为算术右移位,高位补符号位; <<为左移位,低位补0;
1 # 假如将一个无符号的数据val,长度为N,需要循环移动n位。可以利用下面的公式:
2 # 循环左移:(val >> (N - n) | (val << n))
3 # 循环右移:(val << (32 - n) | (val >> n))
4 def ROLN_(val,n,N=8):
5 bit=int('1'*N,2)
6 val &= bit
7 return ((val >> (N - n))&bit) | ((val << n)&bit)
8 def RORN_(val,n,N=8):
9 bit=int('1'*N,2)
10 val &= bit
11 return ((val <<(N - n))&bit) | ((val >> n)&bit)
12
13 a=ROLN_(0x12345678,16,32)
14 b=RORN_(a,16,32)
15 print(hex(a))
16 print(hex(b))
输出:
0x56781234
0x12345678
python3 循环位移动的更多相关文章
- Python3 循环语句
Python3 循环语句 转来的 很适合小白 感谢作者 Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中wh ...
- 【python】Python3 循环语句
[python]几种常见的循环 注意:如果涉及到程序中print语句中含有%d,%s,那么要在脚本最开始写语句:#coding=utf-8,才能够正常输出想要的数字或者字符串. Python3 循环语 ...
- Python3循环语句
Python3 循环语句 Python中的循环语句有for和while. 循环语句控制结构图如下: 一.while循环 ①循环结构 while 判断条件: 执行语句 实例: n = int(input ...
- python013 Python3 循环语句
Python3 循环语句本章节将为大家介绍Python循环语句的使用.Python中的循环语句有 for 和 while.Python循环语句的控制结构图如下所示: while 循环Python中wh ...
- Python3 循环表达式
一 While循环 基本循环 while 条件: 执行内容 #循环体 ... #循环体 ... #循环体 # 若条件为真,执行循环体内容 # 若条件为假,不执行循环体内容 实例1(Python 3.0 ...
- python3循环语句while
Python的循环语句有for和while语句,这里讲while语句. Python中while语句的一般形式: while 条件判断 : 语句 需要注意冒号和缩进.另外,注意Python中没有do. ...
- Python3 循环
Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中while语句的一般形式: while 判断条件: statement ...
- Python3 循环语句(十)
Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中while语句的一般形式: while 判断条件: 语句 同样需要注意 ...
- (三)Python3 循环语句——while
while语句的一般形式: while 判断条件: 语句 同样需要注意冒号和缩进.另外,在 Python 中没有 do..while 循环. 以下实例使用了 while 来计算 1 到 100 的总和 ...
随机推荐
- Pure CSS Progress Chart
Pure CSS Progress Chart CSS Progress Circle SCSS .example { text-align: center; padding: 4em; } .pie ...
- Twitter 分享
Twitter 分享 Twitter Share API https://twitter.com/intent/tweet?url= &text= demo ?url= https://www ...
- shit mint-ui & navbar click event bug
shit mint-ui & navbar click event bug # Vue 2.0 npm install mint-ui -S // 引入全部组件 import Vue from ...
- HTML5 in depth
HTML5 in depth Content Models Web Storage web storage 存储用户信息, 替代 cookies LocalStorage SessionStorage ...
- React Hooks +React Context vs Redux
React Hooks +React Context vs Redux https://blog.logrocket.com/use-hooks-and-context-not-react-and-r ...
- map & scale bug
map & scale TW bug https://antv.alipay.com/zh-cn/g2/3.x/demo/map/drill-down.html import React, { ...
- Nodejs 使用 TypeScript
安装依赖 λ yarn add typescript types/node concurrently nodemon wait-on -D 初始化一个 tsconfig.json λ ./node_m ...
- 解析js字符串
myEval export const evalExp = /[!\&\|\+\-\*\%=\/<\>\^\(\)\~\:\?\;]/g; export function myEv ...
- 华盛顿金融等多家媒体报道VAST超高价值!
近日,华盛顿金融时报联合洛杉矶商业报等多家媒体就即将推出的VAST进行了专题报道. 华盛顿金融时报专栏记者福吉瑞斯问到,之前有报道称NGK官方将全力支持算力市场,那么现在官方有什么计划可以透露一下吗? ...
- Jmeter beanshell编程实例
1.引言 BeanShell是一种小型的,免费的,可嵌入的符合Java语法规范的源代码解释器,具有对象脚本语言特性. 在Jmeter实践中,由于BeanShell组件较高的自由度,通常被用来处理较为复 ...