Tricks to converting from binary to decimal

PigCorpse

[H]ard|Gawd
Joined
Sep 4, 2005
Messages
1,115
Hi,

I'm taking computer programming in high school. Right now, we're doing binary and decimal systems.

I know how to convert between the two bases, but are there any tricks or patterns that can make it faster? For example, converting 1,000,000(10) to base 2 takes quite a while in the normal way.

Thanks
 
all you can do is memorize all the powers of two.

And what kind of shit teacher makes you spend all day converting by hand? Converting one or two digit to binary is ok for an exercise but beyond that is stupid.

PigCorpse said:
Hi,

I'm taking computer programming in high school. Right now, we're doing binary and decimal systems.

I know how to convert between the two bases, but are there any tricks or patterns that can make it faster? For example, converting 1,000,000(10) to base 2 takes quite a while in the normal way.

Thanks
 
The calculator program included with windows can do it for you, though if the teacher wants you to show work, its only useful for verifying that you made no mistakes.
 
RavenD said:
The calculator program included with windows can do it for you, though if the teacher wants you to show work, its only useful for verifying that you made no mistakes.

Or type "1000000 in binary" in the Google search bar.
 
PigCorpse said:
I know how to convert between the two bases, but are there any tricks or patterns that can make it faster? For example, converting 1,000,000(10) to base 2 takes quite a while in the normal way.

Thanks

Explain what you consider to be the "normal" way?
 
Just wait 'til you get to convert floating point back and forth.
biggrin.gif


I did a lot of this kind of thing last semester, and never really found out about a super quick and easy way to do it. Luckily, its not terribly complicated, just a bit tedious.
 
Whatsisname said:
Converting one or two digit to binary is ok for an exercise but beyond that is stupid.
So now converting even a 3 digit binary number is too much hard labor for the delicate young minds of today? :rolleyes:
 
Oh come on!!! When I was at Uni I had to do 32bit numbers

Binary to decimal is easy,
say convert: 1011100101

Code:
  0    1    0   1    1  1   0   0  1  0 1
1024  512  258 128  64  32  16  8  4  2 1


512+128+64+32+4+1

so 1011100101 is 741 in decimal



What do they teach kids these days :rolleyes:




Decimal to Binary is harder, but not much harder :rolleyes:
 
eeyrjmr said:
Oh come on!!! When I was at Uni I had to do 32bit numbers
Binary to decimal is easy,
say convert: 1011100101
Code:
  0    1    0   1    1  1   0   0  1  0 1
1024  512  258 128  64  32  16  8  4  2 1
512+128+64+32+4+1
so 1011100101 is 741 in decimal
What do they teach kids these days :rolleyes:
Decimal to Binary is harder, but not much harder :rolleyes:

Nice technique, but I bet most kids today would struggle with manually doing the addition part ;)

 
eeyrjmr said:
Oh come on!!! When I was at Uni I had to do 32bit numbers
When I was at Uni we had to memorize powers of 2 up to 2^20 just for this very reason.
 
I am surprised that nobody has asked about the signed representation yet, sure, in his example in the OP he mentioned 1,000,000(10) but what about a negative number?
 
Whats the point? If you know how to do 2 or 3 digits you can do virtually any size. Having on an exam a question where you convert 1254365432 to binary has no advantage for proving that you know what you are doing over 143 or 67. All it does is give you more places to make a mistake or waste time.

masher said:
So now converting even a 3 digit binary number is too much hard labor for the delicate young minds of today? :rolleyes:
 
I don't know which method you're using, but one semi-quick way to go from binary to decimal that I use is to work from left to right.

First, skip to the first 1, then for every digit that you move right, if it is a 0, multiply by 2, or if it is a 1, multiply by 2 then add 1. I'll use the same number as the previous guy as an example (1011100101):

Code:
1      0      1      1      1      0      0      1      0      1
------------------------------------------------------------------------------
1      2      5      11     23     46     92     185    370    741
------------------------------------------------------------------------------

Moving Left to Right...

1... skip to the first 1 and start there = 1
0... the 2nd digit is 0 so just multiply 1 by 2 = 2
1... the 3rd digit is 1 so multiply our running total (2) by 2 then add 1 = 5
1... 5x2+1   = 11
1... 11x2+1  = 23
0... 23x2    = 46
0... 46x2    = 92
1... 92x2+1  = 185
0... 185x2   = 370
1... 370x2+1 = 741

1011100101 = 741 yay

Just remember to skip zeroes until you hit the first one! Also, I usually mark the digit I'm on in some way since it really sucks if you have a brain fart while trying to multiply 185 x 2 in your head *cough* and lose your place.

I blame it on the over emphasis my teachers placed on calculators in school, ok?! ;)
 
There is a trick for going from decimal to binary, its not really a trick as much as it is a simple way to look at what you already know.

Basically you keep dividing by two and keep track of the remainder(which will be 1 or 0) until you hit 0.

Say we start with 550 and we want to convert to Base 2.

550/2 = 275 r 0
275/2 = 137 r 1
137/2 = 68 r 1
68/2 = 34 r 0
34/2 = 17 r 0
17/2 = 8 r 1
8/2 = 4 r 0
4/2 = 2 r 0
2/2 = 1 r 0
1/2 = 0 r 1

The binary number is the remainders from bottom to top:
So 550 in base 2 = 1000100110

If you know your powers of two its probably not the quickest, but I like to use that method at times.
 
Uh, I'm very sorry to say that I made a mistake in the question. It was supposed to be:

"How to convert from decimal to binary"

LOL

What I consider the normal way is start with the largest power of 2 smaller than that number. Write a 1, then subtract. Then do the same with the difference and the next smaller power of 2.
 
PigCorpse said:
Uh, I'm very sorry to say that I made a mistake in the question. It was supposed to be:

"How to convert from decimal to binary"

LOL

What I consider the normal way is start with the largest power of 2 smaller than that number. Write a 1, then subtract. Then do the same with the difference and the next smaller power of 2.

Well use the prv post method.
Since binary is just BASE-2 succesive divisions will get the answer
 
Whatsisname said:
all you can do is memorize all the powers of two.

Yeah, tried to do that during my cisco classes, not always the easist thing to do
:p
Just use window's calc in Scientific Mode, Can convert from dec to binary and hex and so on :p
 
So, I can just keep dividing by two until i reach 2^0. Then all the remainders in order will give me the answer?

Ex. 960 > Binary

1/2 = 0 R1
3/2 = 1 R1
7/2 = 3 R1
15/2 = 7 R1
30/2 = 15 R0
60/2 = 30 R0
120/2 = 60 R0
240/2 = 120 R0
480/2 = 240 R0
960/2 = 480 R0

So reading all the remainders from top to bottom, I got 1111000000.
 
Back
Top