我正在尝试创建一个程序,它将输出16个数字的二进制代码。以下是我到目前为止的情况:
#include <stdio.h>
#include <stdlib.h>
int i;
int count;
int mask;
int i = 0xF5A2;
int mask = 0x8000;
int main()
{
printf("Hex Value= %x Binary= \n", i);
{
for (count=0; count<15; count++1)
{
if (i&mask)
printf("1\n");
else
printf("0\n");
}
(mask = mask>>1);
}
return 0;
}
错误:
|16|error: expected ')' before numeric constant|
如果我有任何其他错误,也请告诉我,提前致谢!
答案 0 :(得分:2)
错误是指这个表达式:
count++1
这没有任何意义。
我假设你想要:
count++
制作专栏
for (count=0; count<15; count++)
您的代码中还有其他陌生感,例如:
int i; // Declare an integer named "i"
int mask; // Declare an integer named "mask"
int i = 0xF5A2; // Declare another integer also named "i". Did you forget about the first one???
int mask = 0x8000; // Did you forget you already declared an integer named "mask"?
printf("Hex Value= %x Binary= \n", i);
{
[...]
} // Why did you put a bracket-scope under a PRINTF call?
// Scopes typically follow loops and if-statements!
(mask = mask>>1); // Why put parens around a plain-old expression??
<小时/> 在修复代码中的怪异之后,它应该如下所示:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0xF5A2;
int mask = 0x8000;
printf("Hex Value= %x Binary= \n", i);
for (int count=0; count<15; ++count, mask>>=1)
{
printf("%d\n", (i&mask)? 1 : 0);
}
return 0;
}