gpt4 book ai didi

c - 我无法打印按位运算符的结果

转载 作者:太空狗 更新时间:2023-10-29 15:52:50 25 4
gpt4 key购买 nike

<分区>

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;
}

谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com