[英]Sum of 2 two's complement binary number
I am familiar with two's complement when performing addition in 4 bits, then I am confused when I face the question below我在执行 4 位加法时熟悉二进制补码,然后当我面对以下问题时感到困惑
** Find the sum of the 2 two's complement binary number 010111 and 110101 in 8 bit output** ** 在 8 位输出中找到 2 个二进制补码二进制数 010111 和 110101 的和**
Below is my attempt, but I am in a dilemma, should I以下是我的尝试,但我处于两难境地,我应该
(1) discard the carry, then add two 0, so the answer is 00001100, which is 12 in decimal (1) 丢弃进位,然后加两个0,所以答案是00001100,也就是十进制的12
Thank you !谢谢 !
(2) just add 1 in the beginning, so it the answer is 11001100, which is 204 in decimal (2) 开头加1,所以答案是11001100,也就是十进制的204
For the Twos Complement in 8 bit you have to invert ALL 8 bits of the number对于 8 位的二进制补码,您必须反转数字的所有 8 位
As far as i know the ones complement and twos complement operate on the absolute value so:据我所知,二进制补码和二进制补码对绝对值进行运算,因此:
The Binary Number 010111 is represented in 8 bits with 00010111二进制数 010111 用 00010111 用 8 位表示
C_1(00010111) = 00010111 xor 11111111 = 11101000 C_1(00010111) = 00010111 异或 11111111 = 11101000
C_2(00010111) = C_1 + 1 = 00010111 + 1 = 00011000 C_2(00010111) = C_1 + 1 = 00010111 + 1 = 00011000
The Binary Number 110101 is represented in 8 bits -> 00110101二进制数 110101 用 8 位表示 -> 00110101
C_1(00110101) = 00110101 xor 11111111 = 11001010 C_1(00110101) = 00110101 异或 11111111 = 11001010
C_2(00010111) = C_1 + 1 = 11001010 + 1 = 11001011 C_2(00010111) = C_1 + 1 = 11001010 + 1 = 11001011
Now add the two twos-complements: C_2(00010111) + C_2(00010111) = 00011000 + 11001011 = 11100011现在添加两个补码:C_2(00010111) + C_2(00010111) = 00011000 + 11001011 = 11100011
Pls correct me if messed something up with sign bits (I just took the binary numbers as is in 8 bit)...如果用符号位弄乱了一些东西,请纠正我(我只是按照 8 位的原样取二进制数)...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.