作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个示例代码:
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#ifndef uint32
#define uint32 unsigned long int
#endif
#define L(a) printf("\n%x >> 1 = %x", a, a>>1)
int _tmain(int argc, _TCHAR* argv[])
{
uint32 a = 2941362065;
uint32 b = 509727776;
uint32 c = a ^ b;
L(a^b);
printf("\n%x >> 1 = %x", c , c>>1);
return 0;
}
我的问题是 L(a) 返回
b1304bb1 >> 1 = a0617581
同时
printf("\n%x >> 1 = %x", c , c>>1);
返回
b1304bb1 >> 1 = 589825d8
最后一个值是 Windows 计算器返回的正确值。此代码在 WinXP 32 上运行。有什么想法吗?
最佳答案
L(a^b) becomes printf("\n%x >> 1 = %x", a^b, a^b>>1)
>> 的优先级为 5 而 ^ 为 9(参见 this ),这意味着上面的调用给出与以下相同的结果(注意额外的括号):
printf("\n%x >> 1 = %x", a^b, a^(b>>1))
您应该通过在参数周围添加括号来更改 L 定义:
#define L(a) printf("\n%x >> 1 = %x", (a), (a)>>1)
最好使用函数而不是 L 宏。
关于C++右移、异或问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29003825/
我正在做一个项目,我的 android 在这个项目中作为一个网络服务器工作;输入带端口号的 IP 地址,打开 Web 界面,用户可以将文件上传到手机。我想在 Web 界面上显示一些图片,以便我们的界面
我是一名优秀的程序员,十分优秀!