首页 > 编程知识 正文

二进制的加减运算,二进制加法运算例题

时间:2023-05-04 14:46:20 阅读:43060 作者:4770

二进制加减运算

1 )二进制加法(1)二进制添加(sincebinarynumbersconsistofonlytwodigits0and 1,sotheiradditionisdifferentfromdecimaladition

二进制数由0和1两位数字组成,因此它们的加法与十进制加法不同。 可以根据一些规则添加二进制数。

携带absumcarry0000 110 10 110 1个乙方和000001个01个001个001个01个01个theabovetablecontainstwobitsaandb,their sum and carry。

上表包含和和进位两个位a和b。

开启添加,

在追加时,

0=0,01=1,10=1,11=10 (I.e .sum is 0 and carry is 1) let ' sdosomeexerciseandsolutionsbasedonbinaryary is1)

做一些练习,根据二进制加法解决一些问题,获得更多的主题吧。

example 1:性能(10 )2) 11 ) 2

例1 :执行(10 )2) 11 ) 2

解决方案:

解:

Using the rules provided above,sumoperationcanbeperformedas 3360

使用上述规则,可以按如下方式执行合计运算:

热,(10 )2) 11 )2=) 101 ) 2

因此,(10 )2) 11 )2=(101 ) 2

验证:

验证:

wecanverifyourresultbyconvertingtheabovebinarynumbersintodecimalnumbersandthenverifyingthesum。

可以通过将上述二进制数转换为十进制数并验证合计来验证结果。

Here,10 )2=(2) 10,11 )2=(2)2and ) 101 )2=(2) 10,thuswhenwewilladd2and3wegetsumas 5。

其中(10 )2=(2) 10,) 11 )2=(3) 2和) 101 )2=(5) 10,所以2和3相加,总计为5。

example 2:性能(1)2)1)2)2)1) 2

例2 :执行(1)2)1)2)1)1) 2

解决方案:

解:

Using the rules provided above,sumoperationcanbeperformedas 3360

使用上述规则,可以按如下方式执行合计运算:

example 3:性能(110 )2) 111 )2) 101 ) 2

例3 :执行(110 )2) 111 )2) 101 ) 2

解决方案:

解:

Using the rules provided above,sumoperationcanbeperformedas 3360

使用上述规则,可以按如下方式执行合计运算:

验证:

验证:

wecanverifyourresultas(110 )2=(6) 10,) 111 )2=(6) 10,(101 )2=(6) 10and ) 10010 )2=(6 ) 10.sowhenwhen

验证结果为[110]2=[6]10、[111]2=[7]10、[101]2=[5]10和[10010]2=[18]10。 因此,添加6 7 5=18时,以此为答案。

2 )二进制减法

(2) Binary Subtraction)

The binary subtraction is performed like decimal subtraction, the rules for binary subtraction are:

二进制减法的执行方式类似于十进制减法,二进制减法的规则为:

ABDifferenceBorrow0000011110101100 一个 乙 区别 借 0 0 0 0 0 1个 1个 1个 1个 0 1个 0 1个 1个 0 0

Example 1: Subtract (10)2 from (1001)2

实施例1:减法(10)2从(1001)2

Solution:

解:

In column C2, 1 can't be subtracted from 0 so, we have to borrow 1 from column C3, but C3 also has a 0, so 1 must be borrowed from column C4, the 1 borrowed from column C4 becomes 10 in column C3, now keeping 1 in column C3 bringing the remaining 1 to column C2 which becomes 10 in column C2 thus 10 – 1= 1 in column C2.

在C 2列中,不能从0减去1,因此,我们必须从C 3列中借用1,但是C 3也有0,因此必须从C 4列中借用1,从C 4列中借用1。在列C 3成为如图10所示,现在在列C 3保持1使剩余的1至列C 2,其在列C 2变为10因此10 - 1 = 1在列C 2中 。

In column C3, 1 – 0 = 1

在C 3列中,1 – 0 = 1

In column C4, 1 after providing borrow 1 is reduced to 0.

在C 4列中,提供借位1后的1减少为0。

Therefore, (1001)2 – (10)2 = (111)2

因此, (1001) 2 –(10) 2 =(111) 2

Example 2: Subtract (111.111)2 from (1010.01)2

实施例2:减法(111.111)从2(1010.01)2

Solution:

解:

In Column C0, 1 can't be subtracted from 0, so we have to borrow 1 from column C1, which becomes 10 in column C0, thus 10 – 1 = 1,

在C 0列中,不能从0中减去1,因此我们必须从C 1列中借用1 ,在C 0列中它变为10,因此10 – 1 = 1,

In column C1, after providing borrow 1 to C0, C1 is reduced to 0. Now 1 can't be subtracted from so borrow 1 from C2, but it is also 0, so borrow 1 from C3 which is also 0, so borrow 1 from C4, reducing column C4 to 0. Now, this 1 borrowed from column C4 becomes 10 in column C3, keep 1 in the column C3 and bring other 1 to column C2, which makes column C2 as 10 now again bring 1 from C2 to C1, which reduces C2 to 1 and makes C1 as 10.

在C 1列中,向C 0提供借位1之后,C 1减少为0。现在不能从中减去1,因此从C 2借出1,但是它也为0,因此从C 3借出1也是0,所以由C 4借1,减少列C 4至0。现在,这个1从列C 4借变成10在列C 3中,保持1中的列C 3和带来其它1至柱C 2,这使得列C 2为10现在又将1从C 2带到C 1 ,这将C 2减少为1并使C 1为10。

Thus, In Column C1, 10 – 1 = 1

因此,在列C 1中 ,10 - 1 = 1

In Column C2, 1 – 1 = 0

在C 2列中,1 – 1 = 0

In Column C3, 1 – 1 = 0

在C 3列中,1 – 1 = 0

In Column C4, we now have 1 to be subtracted from 0 which is not possible so we will borrow 1 from Column C5, but Column C5 has a 0 so borrow 1 from C6 making C6 to be 0 and bring it to C5 which makes it 10 in C5, keep 1 in C5 and bring the other 1 to C4 which makes C4 as 10 thus

在C 4列中,现在不可能从0中减去1,这是不可能的,因此我们将从C 5列中借入1,但是C 5列具有0,因此从C 6中借入1,从而使C 6为0并将其取为零。到C 5,这使得它在10的C 5,保持1中的C 5和使其他1至C 4,这使得-C 4作为10因此

In column C4, 10 – 1 = 1

在C 4列中,10 – 1 = 1

In column C5, 1 – 1 = 0

在C 5列中,1-1 = 0

In column C6, 0 – 0 = 0

在C 6列中,0 – 0 = 0

Hence, the result is (1010.01)2 – (111.111)2 = (0010.011)2

因此,结果为(1010.01) 2 –(111.111) 2 =(0010.011) 2

翻译自: https://www.includehelp.com/basics/binary-addition-and-subtraction.aspx

二进制的加减法

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。