Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 汉明或奇偶校验位计算的算法?_Java_Algorithm_Networking_Error Correction_Hamming Code - Fatal编程技术网

Java 汉明或奇偶校验位计算的算法?

Java 汉明或奇偶校验位计算的算法?,java,algorithm,networking,error-correction,hamming-code,Java,Algorithm,Networking,Error Correction,Hamming Code,我正试图编写一个程序来查找java中的汉明码,但对汉明码的计算有点困惑 下面是大多数教程所说的 示例:对于n位消息,例如8位消息,我们需要将k=4奇偶校验位或汉明位置于2的幂次位置(从右到左编号为1到k+n),请参见下面的示例 8 bit message =11000100 k=4 因此 其中P1…P4是奇偶校验位 接下来,为了计算奇偶校验位的值,指令告诉我要盲目地这样做 Each parity bit is calculated as follows: P1 = XOR of b

我正试图编写一个程序来查找java中的汉明码,但对汉明码的计算有点困惑

下面是大多数教程所说的

示例:对于n位消息,例如8位消息,我们需要将k=4奇偶校验位或汉明位置于2的幂次位置(从右到左编号为1到k+n),请参见下面的示例

8 bit message =11000100 
k=4
因此

其中P1…P4是奇偶校验位

接下来,为了计算奇偶校验位的值,指令告诉我要盲目地这样做

Each parity bit is calculated as follows:

    P1 = XOR of bits (3, 5, 7, 9, 11)   =   1⊕1⊕0⊕0⊕0 = 0
    P2  =XOR of bits (3, 6, 7, 10, 11) =   1⊕0⊕0⊕1⊕0 = 0
    P4  =XOR of bits (5, 6, 7, 12)      =   1⊕0⊕0⊕0 = 1
    P8  =XOR of bits (9, 10, 11, 12)   =   0⊕1⊕0⊕0 = 1
有什么方法可以做到这一点,或者我应该记住这个吗?基于他们得到的XOR(3,5…等)。某种算法


注意:要编写一个Java程序来查找任意n位数字的汉明码,我需要对此进行解释,因此我希望这个问题在堆栈溢出中符合要求

该模式以一种更明显的方式显示。啊!现在清楚了,P1从1开始,跳过1,取1,…Pn,从n开始,跳过n,取n!谢谢
Each parity bit is calculated as follows:

    P1 = XOR of bits (3, 5, 7, 9, 11)   =   1⊕1⊕0⊕0⊕0 = 0
    P2  =XOR of bits (3, 6, 7, 10, 11) =   1⊕0⊕0⊕1⊕0 = 0
    P4  =XOR of bits (5, 6, 7, 12)      =   1⊕0⊕0⊕0 = 1
    P8  =XOR of bits (9, 10, 11, 12)   =   0⊕1⊕0⊕0 = 1