c语言如何取数组中的字母,如何从C语言的整数数组中读取2位?

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

另一种解决方案将是一个位域。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值