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 位.
The default operation is 32 bit.
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屋!
查看全文