Skip to content

Latest commit

 

History

History
134 lines (101 loc) · 4.3 KB

File metadata and controls

134 lines (101 loc) · 4.3 KB

P1 假设某分组的信息内容是比特模式 1110 0110 1001 1101,并且使用了偶校验方案。在采用二维奇偶校验方案的情况下,包含该校验比特的字段的值是什么?你的回答应该使用最小长度校验和字段。

1 1 1 0 1
0 1 1 0 0
1 0 0 1 0
1 1 0 1 1
1 1 0 0 0

P2 说明(举一个不同于图 5-5 中那个的例子)二维奇偶校验能够纠正和检测单比特差错,说明(举一个例子)某些双比特差错能够被检测但不能纠正。

P3 假设某分组的信息部分(图 5-3 中的 D)包含 10 字节,它由字符串 "Link Layer" 的 8 比特无符号二进制 ASCII 表示组成。对该数据计算因特网校验和。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "checksum.h"
#include "bin_tool.h"

#define SWAP(_x_) (_x_ = ((_x_ << 8) & 0xFF00) | ((_x_ >> 8) & 0xFF))

int main(int argc, char const *argv[])
{
    if (argc != 2) {
        printf("usage : %s <#msg>", argv[0]);
        exit(1);
    }    

    printAsciiString(argv[1]);

    int len = strlen(argv[1]);
    unsigned short cks = checksum((unsigned short *)argv[1], len);
    SWAP(cks);
    printf("checksum of %s is 【%d】\n",argv[1], cks);
    printf("binary string of cks is 【%s】\n", u16ToBinaryString(cks, EN_GROUP_IN_EIGHTS));
    
    return 0;
}
  • 运行上述程序 test.c 得到如下结果:
progs git:(master) ✗ cc test.c bin_tool.c checksum.c -o test && ./test "Link Layer"
 76 L -> 0100 1100
105 i -> 0110 1001
110 n -> 0110 1110
107 k -> 0110 1011
 32   -> 0010 0000
 76 L -> 0100 1100
 97 a -> 0110 0001
121 y -> 0111 1001
101 e -> 0110 0101
114 r -> 0111 0010
checksum of Link Layer is24051binary string of cks is 01011101 11110011
  • ⚠️

P4 考虑前一个习题,但此时假设这 10 个字节包括。

a. 数字 1 到 10 的二进制表示。

b. 字母 B 到 K (大写) 的 ASCII 表示。

c. 字母 b 到 k (小写) 的 ASCII 表示。

计算这些数据的因特网校验和。

  • a.
#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "checksum.h"
 #include "bin_tool.h"
 
 #define SWAP(_x_) (_x_ = ((_x_ << 8) & 0xFF00) | ((_x_ >> 8) & 0xFF))
 
 int main(int argc, char const *argv[])
 {
     char data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
     unsigned short cks = checksum((unsigned short *)data, 10);
     SWAP(cks);
     printf("checksum is 【%d】\n", cks);
     printf("binary string of cks is 【%s】\n", u16ToBinaryString(cks, EN_GROUP_IN_EIGHTS));
     return 0;
 }
  • 运行上述程序 p4.c 得到下面结果

    progs git:(master) ✗ ./p4                               
    checksum is59105binary string of cks is11100110 11100001
  • b. 运行上述程序得到下面结果

progs git:(master) ✗ ./p4  
  checksum is41115binary string of cks is10100000 10011011
  • c. 运行上述程序得到下面结果
progs git:(master) ✗ ./p4  
checksum is65530binary string of cks is11111111 11111010

P5 考虑 5 比特生成多项式,G = 10011,并且假设 D 的值为 10 1010 1010。R 的值是什么?

P6 考虑上一个习题,这时假设 D 具有值:

a. 10 0101 0101

b. 01 0110 1010

c. 10 1010 0000

  • a.

P7 在这道习题中,我们探讨 CRC 的某些性质。对于在 5.2.3 节中给出的生成多项式 G( =1001),回答下列问题:

a. 为什么它能检测数据 D 中的任何单比特差错?

b. 上述 G 能够检测任何奇数比特差错吗?为什么?