RotateLeft,它做什么? [英] RotateLeft, what does it do?

查看:88
本文介绍了RotateLeft,它做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



#define ROTATE_LEFT(a,n)(((a)<<(n))|(((a)& 0xffffffff)>>(32-( n))))


我一直试图弄清楚这个宏应该做什么。在这里它

以更友好的阅读方式编写:


长无符号RotateLeft(长无符号const值,无符号常量位置)

{

long unsigned x =(value& 0xffffffff); / *仅获得低32位* /


x>> =(32位); / *将它移到右边* /


long unsigned const x = value<<地方; / *向左移动* /


返回x | y;

}


如果我把11111111111111111111111111111111加入a中并且有19个用于

" n",我得到:


x == 11111111111111111111111111111111


(x> ;> = 32-19)==(x>> = 13)== 00000000000001111111111111111111

y == value<< 19 == 11111111111111111110000000000000



x = 00000000000001111111111111111111

y = 11111111111111111110000000000000


我又一次离开了所有人。


Haven无法理解它的假设要做的...


-
$ b $bTomásóhéilidhe

解决方案

< blockquote>

Tomásóhéilidhe < to *@lavabit.com写了留言新闻:Xn ************************** @ 194.125.133.14 ..


>

#define ROTATE_LEFT(a,n)(((a)<<(n))|(( (a)& 0xffffffff)>>(32-(n))))


我一直想弄清楚这个宏应该做什么。这里用更友好的阅读方式编写:


长无符号RotateLeft(长无符号const值,无符号常量位置)

{

long unsigned x =(value& 0xffffffff); / *仅获得低32位* /


x>> =(32位); / *将它移到右边* /

long unsigned const x = value<<地方; / *向左移动* /


返回x | y;

}


如果我把11111111111111111111111111111111加入a中并得到19为n,我得到:



你选择了一个坏榜样。试试0000000000 .... 1作为初始值和

它会更清楚。


x == 11111111111111111111111111111111


( x>> = 32-19)==(x>> = 13)== 00000000000001111111111111111111

y == value<< 19 == 11111111111111111110000000000000



您的y值也是错误的。


I或者他们两个:


x = 00000000000001111111111111111111

y = 11111111111111111110000000000000


我离开了再一次。


Haven无法理解它应该做的事情......


-

Toms hilidhe



Op Sat,05 Jan 2008 21:01:32 GMTschreefTomás óhéilidhe:


#define ROTATE_LEFT(a,n)(((a)<<(n))|(((a)& 0xffffffff) >>(32-(n))))


我一直想弄清楚这个宏应该做什么。在这里它

以更友好的阅读方式编写:


长无符号RotateLeft(长无符号const值,无符号常量位置)

{

long unsigned x =(value& 0xffffffff); / *仅获得低32位* /


x>> =(32位); / *将它移到右边* /


long unsigned const x = value<<地方; / *向左移动* /


返回x | y;

}


如果我把11111111111111111111111111111111加入a中并且有19个用于

" n",我得到:


x == 11111111111111111111111111111111


(x> ;> = 32-19)==(x>> = 13)== 00000000000001111111111111111111

y == value<< 19 == 11111111111111111110000000000000



y == value<< 19 == 11111111111110000000000000000000


>

然后我或他们两个:


x = 00000000000001111111111111111111

y = 11111111111111111110000000000000



y = 11111111111110000000000000000000


>

我和所有人一起离开了。



当然,x是设置了所有位的数字。

选择其中包含一些零的一个,所有都将是透露;-)

-

Coos


Tomas写道:


>

#define ROTATE_LEFT(a,n)(((a)<<(n))|(((a)& 0xffffffff)> >(32-(n))))


我一直想弄清楚这个宏应该做什么。这里

它以更友好的阅读方式编写:


长无符号RotateLeft(长无符号const值,无符号常量位置)

{

long unsigned x =(value& 0xffffffff); / *仅获得低32位* /


x>> =(32位); / *将它移到右边* /

long unsigned const x = value<<地方; / *向左移动* /


返回x | y;

}



您的代码将无法编译。请剪切并粘贴成功编译

代码而不是重新输入。


即使没有编译器错误,功能也不同

在无符号长整数中具有超过32位的实现。


宏/函数实现了旋转操作,这是许多机器上的单个

指令。 br />

-

Thad



#define ROTATE_LEFT(a,n)(((a)<<(n)) | (((a) & 0xffffffff)>>(32-(n))))

I''ve been trying to figure out what this macro is supposed to do. Here it
is written in a more reader-friendly manner:

long unsigned RotateLeft(long unsigned const value,unsigned const places)
{
long unsigned x = (value & 0xffffffff); /* Get lower 32 bits only */

x >>= (32-places); /* Shift it to the right */

long unsigned const x = value << places; /* Shift to the left */

return x | y;
}

If I put 11111111111111111111111111111111 into it for "a" and have 19 for
"n", I get:

x == 11111111111111111111111111111111

(x >>= 32-19) == (x >>= 13) == 00000000000001111111111111111111

y == value << 19 == 11111111111111111110000000000000

I then OR the two of them:

x = 00000000000001111111111111111111
y = 11111111111111111110000000000000

And I''m left with all one''s again.

Haven''t been able to fathom what it''s supposed to do yet...

--
Tomás ó héilidhe

解决方案


"Tomás ó héilidhe" <to*@lavabit.comwrote in message news:Xn**************************@194.125.133.14.. .

>
#define ROTATE_LEFT(a,n)(((a)<<(n)) | (((a) & 0xffffffff)>>(32-(n))))

I''ve been trying to figure out what this macro is supposed to do. Here it is written in a more reader-friendly manner:

long unsigned RotateLeft(long unsigned const value,unsigned const places)
{
long unsigned x = (value & 0xffffffff); /* Get lower 32 bits only */

x >>= (32-places); /* Shift it to the right */
long unsigned const x = value << places; /* Shift to the left */

return x | y;
}

If I put 11111111111111111111111111111111 into it for "a" and have 19 for "n", I get:

You''ve chosen a bad example. Try "0000000000....1" as the initial value and
it will be clearer.

x == 11111111111111111111111111111111

(x >>= 32-19) == (x >>= 13) == 00000000000001111111111111111111

y == value << 19 == 11111111111111111110000000000000

You got the wrong value for "y", also.

I then OR the two of them:

x = 00000000000001111111111111111111
y = 11111111111111111110000000000000

And I''m left with all one''s again.

Haven''t been able to fathom what it''s supposed to do yet...

--
Toms hilidhe



Op Sat, 05 Jan 2008 21:01:32 GMT schreef Tomás ó héilidhe:

#define ROTATE_LEFT(a,n)(((a)<<(n)) | (((a) & 0xffffffff)>>(32-(n))))

I''ve been trying to figure out what this macro is supposed to do. Here it
is written in a more reader-friendly manner:

long unsigned RotateLeft(long unsigned const value,unsigned const places)
{
long unsigned x = (value & 0xffffffff); /* Get lower 32 bits only */

x >>= (32-places); /* Shift it to the right */

long unsigned const x = value << places; /* Shift to the left */

return x | y;
}

If I put 11111111111111111111111111111111 into it for "a" and have 19 for
"n", I get:

x == 11111111111111111111111111111111

(x >>= 32-19) == (x >>= 13) == 00000000000001111111111111111111

y == value << 19 == 11111111111111111110000000000000

y == value << 19 == 11111111111110000000000000000000

>
I then OR the two of them:

x = 00000000000001111111111111111111
y = 11111111111111111110000000000000

y = 11111111111110000000000000000000

>
And I''m left with all one''s again.

Of course, x was the number with all bits set.
Choose one with some zero''s in it and all will be revealed ;-)
--
Coos


Tomas wrote:

>
#define ROTATE_LEFT(a,n)(((a)<<(n)) | (((a) & 0xffffffff)>>(32-(n))))

I''ve been trying to figure out what this macro is supposed to do. Here
it is written in a more reader-friendly manner:

long unsigned RotateLeft(long unsigned const value,unsigned const places)
{
long unsigned x = (value & 0xffffffff); /* Get lower 32 bits only */

x >>= (32-places); /* Shift it to the right */
long unsigned const x = value << places; /* Shift to the left */

return x | y;
}

Your code will fail to compile. Please cut and paste successfully compiled
code instead of retyping.

Even without the compiler error, the functionality is different for
implementations that have more than 32 bits in an unsigned long.

The macro/function implements a rotate operation which is a single
instruction on many machines.

--
Thad


这篇关于RotateLeft,它做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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