2

I'm trying to simulate a Hamming-Code 4,7 which is working properly. I'm working with boolean arrays insted of really bits to simplify it a bit logically. I input some Characters, there converted to ASCII and the Simulation goes on. After all I end up with an BooleanArray of length numberofcharacters*8 where every [] equals one bit. This method should just reconvert this back to ascii code and it work semiproperly. If the ASCII number is even, erverything is fine, but when it's odd the last bit it always 'forgotten'. Thanks for your help

Dear Simon

private static String booleantoString(boolean[] bool){ 
    int[] array = new int[bool.length/8];
    for(int a=0;a<bool.length/8;a++){
        for(int n = a*8; n<(a*8+7); n++){   
            if(bool[n] == true){
                array[a] = setBit(array[a],0);
            }
            array[a] <<= 1;
            }

        System.out.print("ASCII-Code: " + array[a]+ " ");
        System.out.print("Zeichen: " +(char)array[a] + " ");
    }
    return s;   
 }
4

1 回答 1

0

我还没有彻底走完它,但我认为这是一个错误,因为整数除法向下舍入。循环条件bool.length/8似乎特别错误。如果bool.length0-7那么bool.length/80。同样,从那时起任何bool.length8-151。bool.length/8因此,任何尾随数组的不完整字节将始终被忽略。也许尝试将其更改为(bool.length/8)+1.

于 2015-11-09T22:02:51.500 回答