one's-complement 反码, two's-complement 补码, one's complement sum, two's complement sum

1.one's-complement: 反码,高位为符号位;

   two's-complement: 补码,高位为符号位;

 

2. one's complement sum 反码加法,需要加上进位;

    two's complement sum 补码加法,丢弃进位进位;

    例举一个网上的例子: 

2's complement fixed point integers (8-bit)

BinaryDecimalHex
0000 0000000
0000 0001101
0000 0010202
0000 0011303
1111 1111-1FF
1111 1110-2FE
1111 1101-3FD

Let's add two intergers:
-3 + 5 = 2
FD + 05 = 01 02
Discarding the carry (01) gives the correct result.

1's complement fixed point integers (8-bit)

BinaryDecimalHex
0000 0000000
0000 0001101
0000 0010202
0000 0011303
1111 1111-0FF
1111 1110-1FE
1111 1101-2FD
1111 1100-3FC

Add the same numbers:
-3 + 5 = 2
FC + 05 = 01 01
Adding the carry (01) to the LSB (01) gives the correct result:
01 + 01 = 02

So, the 1's complement sum is done by summing the numbers and adding the carry (or carries) to the result..

 

 

参考:Short description of the Internet checksum,http://www.netfor2.com/checksum.html

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值