算术右移

来自GSXAB的知识库
(重定向自右移
算术右移
术语名称 算术右移
英语名称 arithmetic right shift

算术右移(arithmetic right shift)是位运算的一种,指将数据的全部向低位移动并在高位填充最高位的运算。如果二进制串是使用补码表示的有符号整数,则刚好是在进行符号位扩展,这一运算刚好与左移对称。对有符号整数的情况需要与逻辑右移区分。

定义

算数右移
运算名称 算数右移
运算符号
Latex
运算对象 二进制串, 自然数
运算元数 2
运算结果 二进制串
定义域 [math]\displaystyle{ \mathbb{B}^n \times \mathbb{N} }[/math]
陪域 [math]\displaystyle{ \mathbb{B}^n }[/math]

对二进制串 [math]\displaystyle{ b_1 b_2 \cdots b_m }[/math] 和自然数 [math]\displaystyle{ n }[/math] ,得到二进制串 [math]\displaystyle{ \underbrace{b_1 b_1 \cdots b_1}_{n 个 b_1} b_1 b_2 \dots b_{m-n} }[/math] ,称这种运算为算术右移(arithmetic right shift),得到的二进制串称为原二进制串算术右移 [math]\displaystyle{ n }[/math](shifted right by [math]\displaystyle{ n }[/math] (bits) arithmetically)的结果。


位运算
按位运算 按位运算 按位取反按位与按位或按位异或
特殊情况 掩码位设置位清除位反转
移位运算 算术移位 算术左移算术右移
逻辑移位 逻辑左移逻辑右移
循环移位 循环左移循环右移