下面5道诺西题,求个标准答案,都是选择和填空的小题,求个标准答案附加点解释,提前拜年,谢谢
1. Give the results to the following operations(10 points)
0xABCD ^ 0x0F0F =______;0xA15C | 0×9753 =_____;0xB5 & 0×13 =_____;
Int uwData[50];Sizeof(uwData)=___;
Typedef struct{Char *pData[50];} MemStru;
Sizeof(MemStru)=____;
int i ;char unData[100];short cOut;
for(i=0;i<100;i++){ucData[i]=I;}cOut =*(short *)((int *)unData +1);
then ,cOut =___;
1) int * samples 2) const int *samples samples3) int * const samples4) const int *const samples5)volatile const int *const samples
Unsigned char countones(unsigned int data){
}
0xABCD ^ 0x0F0F =0xA4C2;0xA15C
[解决办法]
0×9753 =0xB75F;0xB5 & 0×13 =0x11;//位运算 异或、或、与
int uwData[50];sizeof(uwData)=200;//4*50
typedef struct{char *pData[50];} MemStru;
sizeof(MemStru)=200;//4*50
int i ;char unData[100];short cOut;
for(i=0;i<100;i++){ucData[i]=I;}cOut =*(short *)((int *)unData +1);
then ,cOut =1284;//即0x0504
unsigned char countones(unsigned int data){//不知道为什么返回类型要用unsigned char。。。输出c的ascii即data中1的个数
unsigned char c=0;
unsigned int i=0x80000000;
for(;i>0;i=i>>1){
if((data & i) == i)
c++;
}
return c;
}
int count = 0;
val = val - ((val >> 1) & 0x55555555
val = (val & 0x33333333) + ((val >> 2) & 0x33333333);
count = (((val + (val >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
return count;
3) int * const samples; // samples++__N *samples++__N
4) const int *const samples; // samples++__Y *samples++__N
5)volatile const int *const samples; // samples++__N *samples++__N
*samples++ 等價 *samples; samples++; //很無聊,不知道題目是不是要考 (*samples)++
[解决办法]
unsigned char countones(unsigned int data){
unsigned char c = 0;
while (data) {
data &= data-1
c++;
}
return c;
}
[解决办法]
同意一楼答案;
4楼的:
4)const int *const samples; // samples++__N *samples++__N