Anyone have any tricks for converting binary numbers?

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: TuxDave
Originally posted by: WarDemon666
Ok heres a quickie: convert 258 base 10 to binary. I got 100000001, am I correct? :eek:

*counts the number of zeros.....

100000010


doesnt that give 260? :S Let me look at this again. Maybe its the alchohol. grrr.
 

BespinReactorShaft

Diamond Member
Jun 9, 2004
3,190
0
0
Good luck with this topic WarDemon666. As for myself, it's nice to be reminded of stuff I've forgotten after leaving my school days. Or more often, once the exams are over...

 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
Originally posted by: WarDemon666
Originally posted by: TuxDave
Originally posted by: WarDemon666
Ok heres a quickie: convert 258 base 10 to binary. I got 100000001, am I correct? :eek:

*counts the number of zeros.....

100000010


doesnt that give 260? :S Let me look at this again. Maybe its the alchohol. grrr.

I can cheat since this is a small number and I remember my powers of 2.

258 = 256 + 2 = 2^8+2^1 = 1 and 8 zeros + 1 and 1 zero = 100000010
If you gave me something huge to convert to binary, I would use the divide by 2 method posted above.

 

ttown

Platinum Member
Oct 27, 2003
2,412
0
0
repeated long division. take the number, divide by the base giving you a whole-part and remainder
the remainder is the next "digit" starting on the right
repeat dividing the whole part by the base till all you have are remainders

eg: 5(decimal) in base 2
5/2 = 2 remainder 1 -- right most digit is 1
2/2 = 1 remainder 0 -- next digit left is 0
1/2 = 0 remainder 1 -- next digit left is 1 Answer: 5 decimal = 101 binary

eg2: 45(decimal) in base 16
45/16 = 2 remainder 13 -- 10=A, 11=B, 12=C, 13=D -- right most digit is "D"
2/16 = 0 remainder 2 -- next digit left is 2 Answer: 2D

same idea/method works for any base in the world... base 8, base 5, base 40, whatever....

========
converting to decimal from base <whatever>
right most digit + (base X 2nd-digit-from-the-right) + (base X base X 3rd) + (base X base X base X 4th) +.... etc.

eg: 101 binary = 1 + (2 X 0) + (2 X 2 X 1) == 5
2D hex = 13 + (16 X 2) = 45

tuh-duh! you can now convert anything
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: ttown
repeated long division. take the number, divide by the base giving you a whole-part and remainder
the remainder is the next "digit" starting on the right
repeat dividing the whole part by the base till all you have are remainders

eg: 5(decimal) in base 2
5/2 = 2 remainder 1 -- right most digit is 1
2/2 = 1 remainder 0 -- next digit left is 0
1/2 = 0 remainder 1 -- next digit left is 1 Answer: 5 decimal = 101 binary

eg2: 45(decimal) in base 16
45/16 = 2 remainder 13 -- 10=A, 11=B, 12=C, 13=D -- right most digit is "D"
2/16 = 0 remainder 2 -- next digit left is 2 Answer: 2D

same idea/method works for any base in the world... base 8, base 5, base 40, whatever....

========
converting to decimal from base <whatever>
right most digit + (base X 2nd-digit-from-the-right) + (base X base X 3rd) + (base X base X base X 4th) +.... etc.

eg: 101 binary = 1 + (2 X 0) + (2 X 2 X 1) == 5
2D hex = 13 + (16 X 2) = 45

tuh-duh! you can now convert anything


This is, by far, the wasiest way! I googled once more last night, and found a great site, and thats the way they did it.

Thanks for the help
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
If you spent more than 1 day learning other bases in 7th grade then you went to the nerdiest/geekiest 7th grade in history. You don't need any of that information unless you work with electronics or computers, in which case you need it frequently.
 

ActuaryTm

Diamond Member
Mar 30, 2003
6,858
12
81
Originally posted by: Farvacola
No offense, but I hope your not in college. I learned different bases in 7th grade!
Apparently missed the lesson on the differences between your and you're, however.
 

Gibson486

Lifer
Aug 9, 2000
18,378
2
0
0 0 0=0
0 0 1=1
0 1 0=2
0 1 1=3
1 0 0=4
1 0 1=5
1 1 0=6
1 1 1=7

notice the pattern?
it works for all bits
 

TerryMathews

Lifer
Oct 9, 1999
11,464
2
0
And while we're at it:
Hex : Bin
0-9 are the same as Dec : Bin
A : 1010
B: 1011
C: 1100
D: 1101
E: 1110
F: 1111

If you're in the CEG track, you'll eventually get to the point where hex, dec, and bin all auto-convert in your head. Probably about the same time you complete your second digital logic design class. :) Our final project was designing and implementing a 16 bit CPU.