0

经过几个小时的测试后,我将问题缩小到单个 for 循环,而不是嵌套的 for 循环(第 64 行),如果将数据从 converMain[] 传输到 converMain1[],所有数据都设置为 1,Ive通过,其他一切正常,它只是这个 for 循环。

int converMain[14];
converMain1[0] = 1;
int g = 1;
for (int i = 1; i < 19; i++) {
if (i == 1 || 2 || 4 || 8) { //tests if we are on a parody bit
converMain1[i] = p[i]; //puts parody bit in Main1 array
        g++; //this variable helps sync the bits in the               
                         //right spot in the Main1 array 
    }
    else {
    converMain1[i] = converMain[i - g];         
//puts binary stored in Main array into Main1 array with correct sync
    }
}

输出:

0001011 h 1010011 e 1001111101111111101 0010 392953 104 101 00010111010011
parody bits          ^^ ^   ^
0011011 l 0011011 l 1001111101111111101 0010 392953 108 108 00110110011011
parody bits          ^^ ^   ^
1111011 o 1110111 w 1101011101111111101 1000 392939 111 119 11110111110111
parody bits          ^^ ^   ^
1111011 o 0100111 r 1111011101111111101 1100 392943 111 114 11110110100111
parody bits          ^^ ^   ^
0011011 l 0010011 d 1111111111111111101 1111 393215 108 100 00110110010011
parody bits          ^^ ^   ^
1000010 ! 1000010 ! 1011011101111111101 0100 392941 33 33 10000101000010
parody bits          ^^ ^   ^ 

我们应该期望最右边的数字在中间被串成数字,而箭头忽略箭头的位置,因为这些是模仿位,并且在放下数组的其余部分之前移动它们。

4

1 回答 1

0

if (i == 1 || 2 || 4 || 8)总是正确的。

if ((i == 1) || (2) || (4) || (8))是编译器如何读取它,因此它至少停止,2因为它是真的。

一个自然的解决方案是if (i == 1 || i == 2 || i == 4 || i == 8) ....

于 2019-03-22T21:01:20.433 回答