Anyone have any tricks for converting binary numbers?

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Got an exam coming up in the next few weeks and im having some trouble.

Anyone got any pointers that would help me?

Not only converting base 10,, also base 16 (hex) and subtracting + adding binary numbers....

Thanks.
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Converting anything. I could have any question pop up on the test.

but basically, converting base 10 to binary would help.
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
what we learnt in class was by dividing.

ex. Convert 258(base 10) to binary.

Im guessing i divide 258/10 which is 25.8 so R 1?

Im confused. :S
 

desteffy

Golden Member
Jul 16, 2004
1,911
0
0
keep dividing it by two, and make a list of the remainders. the list of all the remainders when you are done is base 2.

EX.

14 = 2*7 +0
7 = 2*3 +1
3 = 2*1 +1
1 = 2*0 + 1

therefore (14)_{base 10} is equal to (1110)_{base 2}
 

AyashiKaibutsu

Diamond Member
Jan 24, 2004
9,306
4
81
ok basicly with binary you can break it down digit by digit. Lets say it's 8 bits. 1 1 1 1 1 1 1 1 in binary these represent 128 64 32 16 8 4 2 1 in decimal. add them all together and you get 255 the limit for 8 bits. Now for converting to Hex you consider every four binary numbers. so you have the same 8 bits filled with 1s. first 4 numbers adds up to 15 decimal so the hex will be F the second set adds up to 15 as well you you'll get f f as the hex for it. It's the same for converting to to octal but you consider every 3 digits instead of every 4. Now to go to binary from any of these. You find the bigest number that doesn't go over the number your converting. Lets say your converting 129. So the biggest bit you can fit in there would be the 8th one down so that gets a 1. So right now picture it being 1 0 0 0 0 0 0 0. Now look for the next biggest bit that will fit. 64 puts you over as does 32 16 8 4 2, but you find that 1 fits. So your final number will be 1 0 0 0 0 0 0 1.
 

yukichigai

Diamond Member
Apr 23, 2003
6,404
0
76
If you aren't using a calculator....


For base 16 and base 8, in general anything that's a power of 2, you can convert digits from binary -> whatever easily.

Say you have the number 10001110101100011. Lot of numbers. But it's easy to convert to Hex or Octal. You take the power of 2 you're converting to -- the n in 2^n, for octal it's 2^4, hex it's 2^5 -- subtract 1 and convert that many digits at a time. Confused? A demonstration will help.

Okay, we had the number 10001110101100011. Let's convert to octal first. Octal = base 8 = base 2^4, so we convert 3 digits at a time. Separate the number out in groups of 3, starting from the right.

10|001|110|101|100|011

Like so. Now take each one of those groups of 3 and convert them to the octal equivalents.

10 = 2^1 = 2
001 = 2^0 = 1
110 = 2^1 + 2^2 = 2 + 4 = 6
101 = 2^0 + 2^2 = 1 + 4 = 5
100 = 2^2 = 4
011 = 2^0 + 2^1 = 1 + 2 = 3

So you get 216543 in Octal.

Now let's try hex. Hex = base 16 = base 2^5, so convert 4 digits at a time

1|0001|1101|0110|0011

1 = 2^0 = 1
0001 = 2^0 = 1
1101 = 2^0 + 2^2 + 2^3 = 1 + 4 + 8 = 13 = D
0110 = 2^1 + 2^2 = 2 + 4 = 6
0011 = 2^0 + 2^1 = 1 + 2 = 3

So you have 11D63 in Hex


Unfortunately there's no quick way to convert to decimal, since base 10 isn't a power of 2. From a mathematical standpoint it's almost the worst possible number system to use, short of some prime number-based system. (base 7, base 5, etc.) The only way you can really convert by hand is to add up the powers of 2 in the number:

10001110101100011

= 2^0 + 2^1 + 2^5 + 2^6 + 2^8 + 2^10 + 2^11 + 2^12 + 2^16

= 1 + 2 + 32 + 64 + 256 + 1024 + 2048 + 4096 + 65536 = 73059

Really sucks, but that's the only way to do it.
 

raystorm

Diamond Member
Apr 24, 2001
4,712
2
0
Originally posted by: Drakkon
if its odd it ends in 1 if its even it ends in 0 ;)

yea...when it comes to the first bit (the one to the left of the decimal if you are dealing with binary numbers like 100.11 ..etc)

Also, when it comes to fractions: denominator is always even, numerator is always odd (At least thats what I remember)

Those are good things to check when you are done with a problem.
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Thanks a lot guys! Now, ima pour myself another drink, and try this out.

I really apprehiated the replies! :D
 

yukichigai

Diamond Member
Apr 23, 2003
6,404
0
76
No problem. If there's anything you need help with that I didn't cover just say so.
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: yukichigai
No problem. If there's anything you need help with that I didn't cover just say so.

well, for clarification, i tried to add 2 hex numbers. Could u check if i got it right?

4b4
+5c5
____

489? :eek:
 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
Originally posted by: WarDemon666
Originally posted by: yukichigai
No problem. If there's anything you need help with that I didn't cover just say so.

well, for clarification, i tried to add 2 hex numbers. Could u check if i got it right?

4b4
+5c5
____

489? :eek:

4(11)4
+5(12)5
-----------------
9(23)9
------------------
9(7)9
+ 1 0 0 (carry the one)
---------------
(10)79
---------------
A79
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: TuxDave
Originally posted by: WarDemon666
Originally posted by: yukichigai
No problem. If there's anything you need help with that I didn't cover just say so.

well, for clarification, i tried to add 2 hex numbers. Could u check if i got it right?

4b4
+5c5
____

489? :eek:

4(11)4
+5(12)5
-----------------
9(23)9
----------------
(10)79
---------------
A79

Oh so all i have to do is convert the letter to the number it corresponds to, and then change it afterwards?

Thanks! I think i get it. Ill try some from the book now (got the answers)
 

yukichigai

Diamond Member
Apr 23, 2003
6,404
0
76
ERm... no. Let's look at this logically: the lowest number is 4b4. Your result is 489, which is LOWER than 4b4. If you're adding, that's impossible unless one of the numbers is negative.

Just add like you do with decimals. Just remember you're in a different base.

Start with the right side

4 + 5 = 9. Easy enough

b + c = 11 + 12 = 23 = 16 + 7, so 7 and carry a 1
4 + 5 = 9. add the 1 carried from the last digit you get 10. 10 = A

So... A79
 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
Originally posted by: WarDemon666
Originally posted by: TuxDave
Originally posted by: WarDemon666
Originally posted by: yukichigai
No problem. If there's anything you need help with that I didn't cover just say so.

well, for clarification, i tried to add 2 hex numbers. Could u check if i got it right?

4b4
+5c5
____

489? :eek:

4(11)4
+5(12)5
-----------------
9(23)9
----------------
(10)79
---------------
A79

Oh so all i have to do is convert the letter to the number it corresponds to, and then change it afterwards?

Thanks! I think i get it. Ill try some from the book now (got the answers)

That's what I do for hex. Adding binary is much simplier.

_11001
+10010
----------
(2)1011
-----------
101011 (carry the one)
 

WarDemon666

Platinum Member
Nov 28, 2000
2,224
0
0
Originally posted by: yukichigai
ERm... no. Let's look at this logically: the lowest number is 4b4. Your result is 489, which is LOWER than 4b4. If you're adding, that's impossible unless one of the numbers is negative.

Just add like you do with decimals. Just remember you're in a different base.

Start with the right side

4 + 5 = 9. Easy enough

b + c = 11 + 12 = 23 = 16 + 7, so 7 and carry a 1
4 + 5 = 9. add the 1 carried from the last digit you get 10. 10 = A

So... A79


I should have thought the question over before posting my answer.... I get it now..

Thanks! :D
 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
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