逻辑右移,算术右移和旋转右移的区别 [英] The difference between logical shift right, arithmetic shift right, and rotate right

查看:188
本文介绍了逻辑右移,算术右移和旋转右移的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读经典的Hacker的喜悦,但我很难理解逻辑右移,算术右移和右移之间的区别.如果怀疑似乎太简单了,请原谅.

I've been reading the classic Hacker's delight and I am having trouble understanding the difference between logical shift right,arithmetic shift right, and rotate right. Please excuse if the doubt seems too simple.

推荐答案

首先请记住,机器字的大小是固定的.说4,您输入的是:

First remember that machine words are of fixed size. Say 4, and that your input is:

+---+---+---+---+
| a | b | c | d |
+---+---+---+---+

然后将所有内容向左推一个位置会得到

Then pushing everything one position to the left gives:

+---+---+---+---+
| b | c | d | X |
+---+---+---+---+

问X代表什么?

  1. 进行换档并放置0
  2. 旋转并放置a
  1. with a shift put 0
  2. with rotate put a

现在将所有内容向右推一个位置:

Now push everything one position to the right gives:

+---+---+---+---+
| X | a | b | c |
+---+---+---+---+

问X代表什么?

  1. 进行了逻辑移位并放置了0
  2. 具有算术偏移的情况下,将a
  3. 旋转并放置d
  1. with a logical shift put 0
  2. with an arithmetic shift put a
  3. with rotate put d

大约.

逻辑移位对应于(左移位)乘以2,(右移位)整数除以2.

Logical shift correspond to (left-shift) multiplication by 2, (right-shift) integer division by 2.

算术移位与带符号的2的补码表示形式有关.在此表示形式中,符号是最左边的位,然后算术移位会保留符号(这称为符号扩展).

Arithmetic shift is something related to 2's-complement representation of signed numbers. In this representation, the sign is the leftmost bit, then arithmetic shift preserves the sign (this is called sign extension).

旋转没有一般的数学含义,即使在计算机中,也几乎是过时的操作.

Rotate has no ordinary mathematical meaning, and is almost an obsolete operation even in computers.

这篇关于逻辑右移,算术右移和旋转右移的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆