Main      Site Guide    
Message Forum
Decimal to Binary Conversion
Posted By: gremlinn, on host 204.210.33.44
Date: Sunday, November 26, 2000, at 19:48:53
In Reply To: Re: Binary Numbers posted by [Spacebar] on Sunday, November 26, 2000, at 17:58:15:

> > > (1010 -> 8 + 2 = 10).
> > >
> > > -- gremlinn
> >
> > I've never figured out how to derive actual numbers from binary numbers.
> >
> > ~Den-"in deep thought"Kara
>
> It's actually pretty simple.
>
> Let's first consider the numbers we use on a day to day basis; that is, standard "arabic" numbers like 7 (a good number) and 26727 (the index of your post to the message forum). The numbers in our system are called "base 10", what that means is that our numbers can be easily expressed as the sum of numbers multiplied by powers of ten. Let's take 26727 as an example:
>
> / / / 26727
> = 20000 + 6000 + 700 + 20 + 7
> = 2*10^4 + 6*10^3 + 7*10^2 + 2*10^1 + 7*10^0
>
> Any arabic number can easily be expressed in this manner. If I give you a number like 551234 you could instantly tell me that this is equivalent to five-hundred thousands plus five-ten thousands plus one thousand plus two hundred plus three tens plus four. In other words,
>
> 551234 = 5*10^5 + 5*10^4 + 1*10^3 + 2*10^2 + 3*10^1 + 4*10^0
>
> Binary numbers can be understood the same way, except that they are "base 2" instead of "base 10". So you use powers of two instead of powers of ten. For a number like 101101, for example, this would be:
>
> 101101
> = 1*2^5 + 0*2^4 + 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0
> = 45 (I used my calculator for the last step)
>
> Using this system, you can translate any binary number into arabic numbers. (To go backwards, of course, you'd have to figure out how to express a number as the sums of powers of two and then turn that into a binary number. It's harder, but still not that hard.)
>
> -SB

Given a positive integer (X) in decimal, here's a series of steps to convert it to binary (the current digit starts in the digit representing 2^0):

1. If X is even, write '0' in the current digit; if X is odd, write '1' in the current digit and then subtract 1 from X.

2. Shift the current digit one place to the left.

3. If X = 0, you're done. Otherwise, divide X by 2 and go back to step 1.

Replies To This Message