在C循环移位 [英] Circular shift in c

查看:109
本文介绍了在C循环移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以下code的工作,什么变量的意思是:

How does the following code work and what do the variables mean:

y = (x << shift) | (x >> (sizeof(x)*CHAR_BIT - shift));

我在一个循环移位文章,但对如何工作没有解释找到。

I found in a circular shift article but with no explanation on how this works.

推荐答案

CHAR_BIT 是每字节的位数,应为8始终。

CHAR_BIT is the number of bits per byte, should be 8 always.

是要左移以循环方式的比特数,这样得到移出左侧的位,回来就对了。

shift is the number of bits you want to shift left in a circular fashion, so the bits that get shifted out left, come back on the right.

     1110 0000 << 2 results in:
     1000 0011

code的例子:

code for the example:

   y = (x << 2) | (x >> (8 - 2));

这篇关于在C循环移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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