<分区>
Possible Duplicate:
Can I use a binary literal in C or C++?
我无法在C 中显示按位运算符的结果。在下面的代码中,a&b 应为100001 和a|b 111111。但是,打印结果不同。我尝试使用和不使用 itoa 来执行此操作,但无济于事。为什么程序不能正确打印答案?
#include<stdio.h>
#include<stdlib.h>
int main (int argc, char* argv[]) {
unsigned a = 101101;
unsigned b = 110011;
unsigned c = a&b;
unsigned d = a|b;
char s[100];
char t[100];
itoa(c,s,2);
itoa(d,t,2);
printf("%s\n",s); /* Shouldn't it produce 100001?
Instead I get 11000100010101001*/
printf("%s\n",t); /* Ought to print 111111.
Instead it prints 11010111111111111 */
return 0;
}
谢谢