U32 BitMap[6] /* 6 words for 96 persons*/
如何使一个程序,具有循环读取上面的位图6分的话,我们要读每人店员ID 2位,导致tPersonMsg如何从C语言的整数数组中读取2位?
/* 2 Bits representing 00-> default value, 01->Command Successful, 10->Command Failed
* | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* ||--------------------------------------------------------------------------------------------------------------------------------------||||
* | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* ||--------------------------------------------------------------------------------------------------------------------------------------||||
--- similarly for 96 persons*/
得到的结果下列结构中命令失败的人员。
typedef enum eFinalResult {
Succ= 0,
Fail = 1,
noResponse = 2,
} eFinalResult ;
typedef struct {
U32 Person_Id;
tFinalResult Person_Result;
} tResult;
typedef struct {
U32 NumPersons;
tResult Result[32];
} tPersonMsg;
我在这里不是为了激怒任何人,我在C编程初学者
直到现在,我试图让程序如下:
for (i=0; i<6; i++) /* Loop for 6 words*/
{
k = 0;
t= 0x3;
for (j=0; j<31; j+2) /* Loop for bits to reach even position like 0th bit,2nd bit,4th ...and so on*/
{
bits = (a[i] & t) >>j;
k++;
if (a[i] == 2)
{
Command Failed
Person Id = j/2;
}
t = t<<2;
}
}
2015-09-08
Sim
+0
*“命令失败*”哪个命令? –
+0
http://stackoverflow.com/questions/10493411/what-is-masking –
+0
另一种解决方案将是一个位域。 –