1的补码 - 1位或2位错误是否可以检测不到?怎么样?为什么?

时间:2016-11-28 19:20:48

标签: networking tcp header udp packet

在网络数据包标头中,当1位补码与8位字节(而不是TCP中通常使用的16位)一起使用时,1位错误是否会被检测不到?

是否可以检测到2位错误?

如果他们可以如何以及为什么会这样?

1 个答案:

答案 0 :(得分:1)

这是1的补码与3个8位字节一起工作的方式。 (而不是TCP中的16位)

   10011001
+  01010010
___________
   11101011
+  01011001
___________
1  01000100
          1   Wrap Around and add 9th Bit
___________
   01000101  <- Sum
___________
   10111010  <- 1’s Complement

如果有1位错误,它们都将被检测到,但是2位错误可能无法检测到。

   10011000 <- last bit switched (should be 10011001) 
+  01010011 <- last bit switched (should be 01010010)
___________
   11101011
+  01011001
___________
1  01000100
          1 <- Wrap Around and add 9th Bit
___________
   01000101 <- Sum
___________
   10111010 <- 1’s Complement with 2 bit error is the same as previous answer