當前位置:編程學習大全網 - 網站源碼 - UDP為什麽使用反碼作為校驗和?

UDP為什麽使用反碼作為校驗和?

It may look awkword to use a 1's complement addition on 2's complement machines. This method however has its own benefits.\x0d\Probably the most important is that it is endian independent. Little Endian computers store hex numbers with the LSB last (Intel processors for example). Big Endian computers put the LSB first (IBM mainframes for example). When carry is added to the LSB to form the 1's complement sum (see the example) it doesn't matter if we add 03 + 01 or 01 + 03. The result is the same.\x0d\Other benefits include the easiness of checking the transmission and the checksum calculation plus a variety of ways to speed up the calculation by updating only IP fields that have changed.\x0d\ 上面是原文的壹部分,說明在TCP/IP校驗和中使用反碼求和的壹些優點:\x0d\\x0d\校驗和使用反碼求和的優點是:不依賴系統是大端小端。即無論妳是發送方計算機或者接收方檢查校驗和時,都不要調用htons或者ntohs,直接通過上面的算法就可以得到正確的結果。這個問題妳可以自己舉個例子,用反碼求和時,交換16位數的字節順序,得到的結果相同,只是字節順序相應地也交換了;而如果使用原碼或者補碼求和,得到的結果可能就不同。

  • 上一篇:EMQ 怎麽樣?好用嗎?
  • 下一篇:啟用ECM後,如何控制當修改bom或其它主檔資料時必須輸入ECN,否則不能修改?
  • copyright 2024編程學習大全網