用0xffffffff进行按位与运算的无符号长 [英] bitwise anding unsigned long with 0xffffffff

查看:148
本文介绍了用0xffffffff进行按位与运算的无符号长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是switch语句中的一些代码. getvalue()返回unsigned long. 有人可以解释为什么value0xffffffff进行按位运算. 单片机是32位.

Below is some code from switch statement. getvalue() returns an unsigned long. Could somebody explain why value is bitwise anded with 0xffffffff. The mcu is 32 bit.

#define WriteMemory(A,V) *(volatile unsigned long*)(A)=(V)
static unsigned value;

case 'b':
value = getvalue();
value &= 0xffffffff;
WriteMemory(2147455555, value);
break; 

推荐答案

unsigned long由C标准不能保证为32位.只能保证能够容纳32位值.

unsigned long isn't guaranteed to be 32 bit by the C standard. It is only guaranteed to be able to hold 32 bit values.

0xffffffff进行对接,以确保32位上的所有位都被清零.

and-ing it with 0xffffffff makes sure any bits over the 32 are zeroed out.

这篇关于用0xffffffff进行按位与运算的无符号长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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