C对uint64_t变量进行按位移位操作 [英] Bitwise shift operation in C on uint64_t variable
本文介绍了C对uint64_t变量进行按位移位操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下示例代码:
uint64_t x, y;
x = ~(0xF<<24);
y = ~(0xFF<<24);
结果将是:
x=0xfffffffff0ffffff
y=0xfffff
有人可以解释区别?为什么x是在64位上计算而y仅在32位上计算?
Can anyone explain the difference? Why x is calculated over 64 bit and y only on 32?
推荐答案
默认操作是32位。
x=~(0xf<<24);
此代码可以分解为以下步骤:
This code could be disassembled into the following steps:
int32_t a;
a=0x0000000f;
a<<=24; // a=0x0f000000;
a=~a; // a=0xf0ffffff;
x=(uint64_t)a; // x = 0xfffffffff0ffffff;
而且,
y = ~(0xFF<<24);
int32_t a;
a=0x000000ff;
a<<=24; // a=0xff000000;
a=~a; // a=0x00ffffff;
x=(uint64_t)a; // x = 0x000000000ffffff;
这篇关于C对uint64_t变量进行按位移位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文