32位处理器下64位整型的移位操作

01 INT64 move_left(UINT64 x, INT8 count)
02 {
03     UINT32 * p = (UINT32 *)(&x);
04    
05     if (count < 32)
06     {
07         *(p + 1) <<= count;
08         *(p + 1) |= (*p) >> (32 count);
09         *p <<= count;
10     }
11     else
12     {
13         *(p + 1) = *p;
14         *p = 0x00000000;
15         *(p + 1) <<= (count 32);
16     }
17    
18     return x;
19 }

 
01 INT64 move_right(UINT64 x, INT8 count)
02 {
03     UINT32 * p = (UINT32 *)(&x);
04
05     if (count < 32)
06     {
07         *p >>= count;
08         *p |= *(p + 1) << (32 count);
09         *(p + 1) >>= count;
10     }
11     else
12     {
13         *p = *(p + 1);
14         *(p + 1) = 0x00000000;
15         *p >>= (count 32);
16     }
17
18     return x;
19 }

发表评论

电子邮件地址不会被公开。 必填项已用*标注