2016-02-08 46 views
-2

我想创建一个程序,将输出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

什么错误? – Jacobr365

+0

哇对不起,这是“预期”)'数字常数之前“ – phunguz

+0

'count ++ 1' - >'count ++''。还有'(mask = mask >> 1);'进入For循环 – BLUEPIXY

回答

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; 
} 
相关问题