转换的十进制数转换为二进制 [英] Converting a decimal number into binary

查看:143
本文介绍了转换的十进制数转换为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在读查尔斯Petzold的书code'。他在文中解释了如何使用以下模板转换成十进制数转换成二进制:

I am currently reading Charles Petzold's book 'Code'. In it he explains how to convert a decimal number into binary using the following template:

                [ ]   [ ]   [ ]   [ ]   [ ]   [ ]   [ ]   [ ]
                ÷128  ÷64   ÷32   ÷16   ÷8    ÷4    ÷2    ÷1
                [ ]   [ ]   [ ]   [ ]   [ ]   [ ]   [ ]   [ ]

在这本书中,他解释了如何使用模板上写着:

In the book, his explanation on how to use the template reads:

把整个十进制数(小于或等于255)在上部的框 左上角。除以数(被除数)由第一除数(128),如 表示。放的商在下面(在左下角的框)的框,并 其余在右侧框中(顶行的第二个框)。该第一剩余是被除数对下一次计算,它使用64的除数通过模板继续以相同的方式。

"Put the entire decimal number (less than or equal to 255) in the box in the upper left corner. Divide that number (the dividend) by the first divisor (128), as indicated. Put the quotient in the box below (the box at the lower left corner), and the remainder in the box to the right (the second box on the top row). That first remainder is the dividend for the next calculation, which uses a divisor of 64. Continue in the same manner through the template.

请记住,每个商将是0或1。如果被除数小于除数的商为0,余数是单纯的分红。如果被除数是大于或等于除数,商为1,其余的是除法器 - 除数。下面是它如何与150进行

                [150]  [22]   [22]   [22]   [6 ]   [6 ]   [2 ]   [0 ]
                ÷128   ÷64    ÷32    ÷16    ÷8     ÷4     ÷2     ÷1
                [1 ]   [0 ]   [0 ]   [1 ]   [0 ]   [1 ]   [1 ]   [0 ]

但我不解!当我这样做的指示的计算,我得到非常不同的结果。我在做什么如下:

But I'm puzzled! When I do the calculations as instructed, I'm getting very different results. What I'm doing is as follows:

150÷128 = 1.171875 (我没有看到那里的22来自上面?)所以,我把一个1在150下方的复选框,然后携带的 171875 和使用,作为股息为下一个计算,这当然让我到各种各样的问题,最终,而不是二进制数10010110!

150 ÷ 128 = 1.171875 (I don't see where the 22 comes from above?) So, I place a 1 in the box below the 150 and then carry the 171875 and use that as the dividend for the next calculation, which of course gets me into all sorts of problems, and ultimately, not the binary number 10010110!

有人可以告诉我,我要去哪里错了?

Can somebody tell me where I'm going wrong?

推荐答案

22为的一百二十八分之一百五十零剩余部分。

22 is the remainder of 150/128.

既然你已经确定有1 128,在150,并赋予一个值,位,你可以忘记的128这是在150,让你从150把它拿走,留给我们的22。它的时候了数字价值64:64不进入22,这样的数字是0。同样地,对于数字值得32。然后对位身价16:16进入22一次,所以有1位的有,现在你带中的22 16完成的,所以把它拿走 - 留下6.等等

Since you've determined that there's 1 128 "in" 150, and given a value to that bit, you can forget about the 128 that's "in" 150, so you take it away from 150, leaving our 22. Then it's time for the digit worth 64: 64 doesn't go into 22, so that digit is a 0. And similarly for the digit worth 32. Then for the digit worth 16: 16 goes into 22 once, so there's a 1 digit there, and now you're done with the 16 "in" 22, so take it away -- leaving 6. And so on.

(考虑一个类似的基数为10的情况下,假设309乘100秒列;有3个100秒309,让你把一个3那里,现在有9遗留下来再取10秒列;还有0 10秒9,所以你把0那里,然后在1秒列:。有9个1秒9,让你把一个9在那里,现在什么都不剩 - 就大功告成了)

(Consider a similar base 10 case, let's say 309. Take the 100s column; there are 3 100s in 309, so you put a 3 there. And now there's 9 left over. Then take the 10s column; there are 0 10s in 9, so you put a 0 there. And then the 1s column: there are 9 1s in 9, so you put a 9 in there. And now there's nothing left -- you're done.)

我有一种可怕的感觉,这可能会混淆超过澄清,但这是我怎么想也无妨。

I have a horrible feeling this might confuse more than clarify, but that's how I think of it anyway.

这篇关于转换的十进制数转换为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆