二进制补码乘法除法_二进制乘法和除法

二进制补码乘法除法

1)二进制乘法 (1) Binary Multiplication)

Binary numbers can be multiplied using two methods,

二进制数可以使用两种方法相乘,

  1. Paper method: Paper method is similar to multiplication of decimal numbers on paper.

    纸张方法:纸张方法类似于纸张上十进制数字的乘法。

  2. Computer method: Computer method is used by digital machines to multiply the binary numbers.

    计算机方法:数字计算机使用计算机方法乘以二进制数。

However, both these methods follow the same rule of multiplication which is,

但是,这两种方法都遵循相同的乘法规则,即

    0 * 0 = 0
0 * 1 = 0
1 * 0 = 0
1 * 1 = 1

Note: If two binary numbers are of 'n' bits each in magnitude, then their product can be maximum '2n' bits long in magnitude.

注意:如果两个二进制数的大小均为'n'位,则它们的乘积最大为'2n'位。

长手乘法/纸张方法 (Long Hand Multiplication/Paper Method)

The long Hand Multiplication technique is similar to decimal multiplication that we do on paper.

长手乘法技术类似于我们在纸上进行的十进制乘法。

In this technique, we multiply the multiplicand with each bit of multiplier and add the partial products together to obtain the result.

在这项技术中,我们将被乘数与乘数的每一位相乘,并将部分乘积相加以获得结果。

We scan the multiplier from the RHS, if the multiplier bit is 1 then we copy the whole multiplicand in the partial product and if the multiplier bit is 0, we replace all the bits of the multiplicand with 0 in the partial product.

我们从RHS扫描乘数,如果乘数位为1,则复制部分乘积中的整个被乘数,如果乘数位为0,则将乘积中的所有位替换为部分乘积中的0。

Example 1: Compute (10)2 * (11)2

示例1:计算(10) 2 *(11) 2

Solution:

解:

binary multiplication 1

Therefore, the result is (10)2 * (11)2 = (110)2

因此,结果是(10) 2 *(11) 2 =(110) 2

Verification:

验证:

We can verify our result by converting the binary numbers to respective decimal numbers and multiplying them to get the result.

我们可以通过将二进制数字转换为相应的十进制数字并乘以它们以获得结果来验证我们的结果。

Here, (10)2 = (2)10, (11)2 = (3)10 and (110)2 = (6)10. When we will multiply 2 and 3, we will get the product as 6, which we are getting by multiplication of binary numbers. Hence our solution is correct.

在此, (10) 2 =(2) 10(11) 2 =(3) 10(110) 2 =(6) 10 。 当我们将23相乘时,我们将得到乘积为6 ,这是通过二进制数相乘得到的。 因此,我们的解决方案是正确的。



Example 2: Compute (111)2 * (101)2

示例2:计算(111) 2 *(101) 2

Solution:

解:

binary multiplication 2

Therefore, the result is (111)2 * (101)2 = (100011)2

因此,结果为(111) 2 *(101) 2 =(100011) 2



Example 3: Compute (1010.01)2 * (1.01)2

示例3:计算(1010.01) 2 *(1.01) 2

Solution:

解:

binary multiplication 3

Therefore, the result is (1010.01)2 * (1.01)2 = (1100.1101)2

因此,结果为(1010.01) 2 *(1.01) 2 =(1100.1101) 2

2)二进制除法 (2) Binary Division)

Like binary multiplication, division of binary numbers can also be done in two ways which are:

像二进制乘法一样,二进制数的除法也可以通过两种方式完成:

  1. Paper Method: Paper Method division of binary numbers is similar to decimal division.

    纸张方法 :纸张方法对二进制数的除法类似于十进制除法。

  2. Computer Method: Computer Method is used by the digital devices where they make use of 2's complement of a number to subtract the numbers during division.

    计算机方法 :数字设备使用数字方法使用数字的补码来在除法运算中减去数字。

长手分割法/纸法 (Long Hand Division Method/Paper Method)

In binary division, there are only two possibilities either 0 or 1. If the divisor goes into the dividend then quotient will be 1 and if the divisor doesn’t then the quotient will be 0. Similar, to decimal division, we will subtract divisor from the dividend and the result will be appended by the next bit in the dividend. This process repeats until all the bits of the dividend are considered.

二进制除法中 ,只有两种可能性,即0或1。如果除数进入被除数,则商将为1;如果除数没有,则商将为0。类似于十进制除法,我们将减去除数的红利和结果将被添加到红利的下一位。 重复此过程,直到考虑了除数的所有位。

Example 1: Divide (111101)2 by (100)2

范例1:将(111101) 2除以(100) 2

Solution:

解:

binary division 1

Therefore, the result is (111101)2 / (100)2 gives (1111)2 (Quotient) and 1 (Remainder)

因此,结果为(111101) 2 /(100) 2得出(1111) 2 (商)和1(余数)



Example 2: Divide (110101.11)2 by (101)2

范例2:将(110101.11) 2除以(101) 2

Solution:

解:

binary division 2

Therefore, the result is (110101.11)2 / (101)2 gives (1010.11)2.

因此,结果为(110101.11) 2 /(101) 2给出(1010.11) 2

Verification:

验证:

We can verify our result by converting the binary numbers to respective decimal numbers and then dividing the dividend by the divisor to get the result.

我们可以通过将二进制数字转换为相应的十进制数字,然后将除数除以除数来得到结果,从而验证我们的结果。

Here, (110101.11)2 = (53.75)10, (101)2 = (5)10 and (1010.11)2 = (10.75)10. When we will divide 53.75 by 5, we will get the result as 10.75, which we are getting by doing division of binary numbers. Hence our solution is correct.

在此, (110101.11) 2 =(53.75) 10(101) 2 =(5) 10(1010.11) 2 =(10.75) 10 。 当我们将53.75除以5时 ,将得到10.75的结果,这是通过对二进制数进行除法得到的。 因此,我们的解决方案是正确的。



Example 3: Divide (1010.1)2 by (101.01)2

示例3:将(1010.1) 2除以(101.01) 2

Solution:

解:

binary division 3

Therefore, the result is (1010.1)2 / (101.01)2 gives (10)2.

因此,结果是(1010.1)2 /(101.01)2给出了(10)2。

翻译自: https://www.includehelp.com/basics/binary-multiplication-and-division.aspx

二进制补码乘法除法

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544081.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

控制JSP头部引入外部文件编译后在第一行

2019独角兽企业重金招聘Python工程师标准>>> 一.错误引入方法 假设当前需要在JSP页面输出xml格式数据,需要引入以下外部文件,通过以下的方式来引入则无法正常输出数据: 访问页面会报错误:xml的声明不在文档的第一行 看…

ruby hash方法_Ruby中带有示例的Hash.values方法

ruby hash方法哈希值方法 (Hash.values Method) In this article, we will study about Hash.values Method. The working of the method can be assumed because of its very common name but there exist some hidden complexities too. Let us read its definition and unde…

4种常见的缓存模式,你都知道吗?

概述 在系统架构中,缓存可谓提供系统性能的最简单方法之一,稍微有点开发经验的同学必然会与缓存打过交道,最起码也实践过。如果使用得当,缓存可以减少响应时间、减少数据库负载以及节省成本。但如果缓存使用不当,则可能…

php yii多表查询

一个Company记录可以对应多个CompanyUser纪录Company表: [[id, nature_id, scale_id, pro_id, created_at, updated_at], integer], [[id,company_name], required], [[company_logo,company_desc,company_name,nature,scale,pro], string] public function getCompanyuser() {…

ruby hash方法_Ruby中带有示例的Hash.rehash方法

ruby hash方法Hash.rehash方法 (Hash.rehash Method) In this article, we will study about Hash.rehash Method. The working of the method cant be assumed because of its quite a different name. Let us read its definition and understand its implementation with th…

面试突击63:distinct 和 group by有什么区别?

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)在 MySQL 中,最常见的去重方法有两个:使用 distinct 或使用 group by,那它们有什…

从20s优化到500ms,我用了这三招

前言接口性能问题,对于从事后端开发的同学来说,是一个绕不开的话题。想要优化一个接口的性能,需要从多个方面着手。本文将接着接口性能优化这个话题,从实战的角度出发,聊聊我是如何优化一个慢查询接口的。上周我优化了…

camelcase_在Python中将字符串转换为camelCase

camelcaseHere, we are implementing a python program to convert a given string to camelCase. 在这里,我们正在实现一个python程序,将给定的字符串转换为camelCase。 Example of camelCase: camelCase的示例: String: "Hello worl…

面试拆解:系统上线后CPU急速飙升,该怎么排查?

上次面试官问了个问题:应用上线后Cpu使用率飙升如何排查?其实这是个很常见的问题,也非常简单,那既然如此我为什么还要写呢?因为上次回答的时候我忘记将线程PID转换成16进制的命令了。所以我决定再重温一遍这个问题&…

提高Python运行效率的六个窍门

Python性能优化的20条建议 http://segmentfault.com/a/1190000000666603优化算法时间复杂度 算法的时间复杂度对程序的执行效率影响最大,在Python中可以通过选择合适的数据结构来优化时间复杂度,如list和set查找某一个元素的时间复杂度分别是O(n)和O(1)。…

ruby hash方法_Hash.fetch()方法以及Ruby中的示例

ruby hash方法Hash.fetch()方法 (Hash.fetch() Method) In this article, we will study about Hash.fetch() Method. The working of this method can be predicted with the help of its name but it is not as simple as it seems. Well, we will understand this method wi…

MySQL 死锁了,怎么办?

作者:小林coding提纲如下:正文有个业务主要逻辑就是新增订单、修改订单、查询订单等操作。然后因为订单是不能重复的,所以当时在新增订单的时候做了幂等性校验,做法就是在新增订单记录之前,先通过 select ... for upda…

lcfirst_PHP lcfirst()函数与示例

lcfirstPHP lcfirst()函数 (PHP lcfirst() function) lcfirst() function is a string function, it is used to convert first character to lowercase. It accepts string and returns string with first lowercase character. lcfirst()函数是一个字符串函数,用于…

在notepad++中运行python代码

#在notepad中运行python代码1、安装插件pyNPP, 2、允许插件pyNPP中的第一个和第二个选项即可,如果代码过少代码执行一闪而过,可能无法看到,可加入少量sleep时间即可 方法二:1、安装插件NppExec2、打开NppExec--Execute…

10 张图搞懂服务注册发现机制

在微服务架构或分布式环境下,服务注册与发现技术不可或缺,这也是程序员进阶之路必须要掌握的核心技术之一,本文通过图解的方式带领大家轻轻松松掌握。引入服务注册与发现组件的原因先来看一个问题,假如现在我们要做一个商城项目&a…

c# datetime._C#| DateTime.GetHashCode()方法与示例

c# datetime.DateTime.GetHashCode()方法 (DateTime.GetHashCode() Method) DateTime.GetHashCode() method is used get the 32-bit signed integer hash code of DateTime class object. DateTime.GetHashCode()方法用于获取DateTime类对象的32位带符号整数哈希码。 Syntax:…

ASP.NET 5 Beta8 已经发布

Microsoft ASP.NET and Web Tools 2015 (Beta8) http://www.microsoft.com/en-us/download/details.aspx?id49442 .net core 完成了98%,绝大部分类库完成了跨平台开发,已经基本可用,下一版本为RC,发布时间为12月,将可…

面试突击65:HTTPS有什么优点?说一下它的执行流程?

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)说到 HTTPS 相信大部分人都是不陌生,因为目前我们使用的绝大数网站都是基于 HTTPS 的,比如以…

nanf flash校验_C ++中带有示例的nanf()函数

nanf flash校验C Nanf()函数 (C nanf() function) nanf() function is a library function of cmath header, it is used to get the NaN value of type float. It accepts an argument (which is an implementation-specific C String – to get NaN value we have to pass a…

Cell.reuseIdentifier 指什么

Cell.reuseIdentifier 指的是 默认为空,如果不定义,在执行 [_tableView registerNib:templateCellNib forCellReuseIdentifier:_templateCell.reuseIdentifier]; 时,提示 must pass a valid reuse identifier to -[UITableView registerNib:f…