按位转移字符的数组

问题描述:

我已经得到了我想要逐位右移字符数组>> ,那么&安培; 与另一个数组。我想我已经得到了如何做到这一点的错误观念。

I have got an array of chars that I'm trying to bitwise shift right >>, then & with another array. I think I have got the wrong idea of how to do this.

我想,即使是字符只是陈述 my_array&GT的数组;> = 1 将转移的一切,但我得到了一个错误:错误:无效的操作数为二进制>>(有'的char [8]和INT)

I thought, even though it was an array of chars just stating my_array >>= 1 would shift everything but I am getting an error: "error: invalid operands to binary >> (have ‘char[8]’ and ‘int’)"

按位比较,我试图做的是开始对所有0的类似大小的数组......对于我得到:错误:无效的操作数为二进制及(有'字符*'和'字符*')

The bitwise comparision I am trying to do is with a similar size array initiated to all "0's"...for that I'm getting: "error: invalid operands to binary & (have ‘char *’ and ‘char *’)"

我是否需要这些数组转换成别的东西之前,我可以转移和比较?

Do I need to convert these array's into something else before I can shift and compare?

对不起,我是不是超清晰......所有伟大的意见到这点,我想我意识到更是没有超级简单的方法来做到这一点。更具体地讲,我所要做的是用同样大小的另一个数组转向整个字符数组右1位,加上位移出右后卫到阵列的最左侧,做到逐位进行比较。

Sorry, I was not super clear... All great advice up to this point and I think I am realizing more that there is no super easy way to do this. More specifically, what I am trying to do is shift the bits of the WHOLE char array right 1, adding the bit shifted off the right back to the left most side of the array, do the bitwise compare with another array of same size.

在技术上比较并不一定是数组的数组...我需要的只是位。尝试做轮班/比较之前别的阵列的转换的东西会是更容易?

Technically the compare doesn't have to be array with array... I just need the bits. Would it be easier to convert the array's to something else before trying to do the shifts/comparisons?

您必须转移和比较的elementwise

You have to shift and compare elementwise.

for(i = 0; i < len; ++i)
    array[i] >>= 3;

例如。如果要移动的位移出一个元素的下一个,它更复杂,说你右移,然后

for example. If you want to move the bits shifted out of one element to the next, it's more complicated, say you're shifting right, then

unsigned char bits1 = 0, bits2 = 0;
for(i = len-1; i >= 0; --i) {
    bits2 = array[i] & 0x07;
    array[i] >>= 3;
    array[i] |= bits1 << 5;
    bits1 = bits2;
}

遍历在其他方向上的数组,因为你从下一个更高的时隙所需要的位

traversing the array in the other direction because you need the bits from the next higher slot.