int main() {
int a[3] = { 0x0f,0x0f,0x0f }, b[3] = {0,0,0};
int t = 0,tt;
t |= a[0] << 16;
t |= a[1] << 8;
t |= a[2];
t = t >> 3;
tt = t;
printf("0x%x
",t);
b[0] |= t >> 16;
tt &= 0xff00;
b[1] |= tt >> 8;
t &= 0xff;
b[2] |= t;
for (int j = 0; j < 3; j++)
{
printf("b[%d]=0x%x
",j,b[j]);
}
}
int a[3] = { 0x0f,0x0f,0x0f }, b[3] = {0,0,0};
int t = 0,tt;
t |= a[0] << 16;
t |= a[1] << 8;
t |= a[2];
t = t >> 3;
tt = t;
printf("0x%x ",t);
b[0] |= t >> 16;
tt &= 0xff00;
b[1] |= tt >> 8;
t &= 0xff;
b[2] |= t;
for (int j = 0; j < 3; j++)
{
printf("b[%d]=0x%x ",j,b[j]);
}
}
是吧几个数据与了然后偏移吗?可是这样的话如果我超过4byte了 就不止32位了
如果元素个数是三个,问题比较简单,可如果个数未知就只能单个右移了。
对以,你要求左移,怎么你右移了呢?
#include <stdio.h>
int main(void)
{
unsigned char a[3] = {0x0f,0x0f,0x0f};
unsigned int* p = (unsigned int*)a;
*p = (*p) >> 3;
printf("右移三位是:%d ", *p);
}
一周热门 更多>