Author Topic: Binary Conversions  (Read 1623 times)

February 15, 2004, 07:50:25 AM
Read 1623 times

Lito

  • Legacy Reserved
  • Fade

  • Offline
  • **

  • 489
    • View Profile
    • http://
i need some help on conversions namely

Decimal to Base2
Decimal to Hex
Decimal to Oct
Decimal to Basen (where n is any integer)

and i need to know how to backwards convert it too,
AND how to convert between them, ie
Base2 to hex
Hex to Oct
etc.
Go, go, go, Johnny, go, go, go
Go, Johnny, go, go, go
Go, Johnny, go, go, go
Go, Johnny, go, go, go
aah - Johnny B. GONE
sig images must not exceed 22kb -DHP


Thanks to Bijiy for help on the sig
Japanese Lesbian Kissing ftw
Waffles aer teh lews.

February 15, 2004, 09:31:21 AM
Reply #1

Satanic Monkey

  • Legacy Reserved
  • Fade

  • Offline
  • **

  • 262
    • View Profile
    • http://www.thecatacombs.net
Decimal ----> 192
binary   -----> 11000000
                           128 64 32  16 8 4 2 1
For binary, where the 1's are, that's what you add. Therefore 128 +64= 192

Deciimal ----> 192
Hex ------> 1100 0000 Put it in binary form first , but broke i down in half like this ---> 1100 0000 and for each one do the order from right to left 8 4 2 1 8 4 2 1 and add up. So 1100 will be  12 and 0000 will be 0 so it will be C 0.
 I don't know about oct and the basen so this is all i can do.
« Last Edit: February 15, 2004, 09:31:52 AM by Satanic Monkey »
Don't mess with me punk, I'll post in your

February 15, 2004, 11:37:22 AM
Reply #2

Legionnaired

  • Legacy Reserved
  • Fade

  • Offline
  • **

  • 492
    • View Profile
    • http://
All number systems work as follows:

n^6 n^5 n^4 n^3 n^2 n^1 n^0

Where n equals the base of the number system. You can convert it to base 10 so you can understand it, then back to whatever you need it to be.
« Last Edit: February 15, 2004, 11:37:56 AM by Legionnaired »

February 15, 2004, 01:20:38 PM
Reply #3

JHunz

  • Legacy Reserved
  • Onos

  • Offline
  • ***

  • 536
    • View Profile
    • http://
Decimal to basen:
Find the largest power of n smaller than the number.  Subtract until the number is less than that.  Put the number of times you subtracted into the proper place in the
structure Leaderz0rz described.
Example: 213 decimal to base 5
5^3 = 125
213 - 125 = 88    So far, we have 1000
5^2 = 25
88 - 25 = 63 - 25 = 38 - 25 = 13   Now, we have 1300
5^1 = 5
13 - 5 = 8 - 5 = 3  Now, we have 1320
Now just put the remainder in the last column, for a result of 1323 base5

Basen to decimal:
this is easy.  Start at the rightmost digit, this is ones.  Now, the one to the left is n's.  The one to the left of this is n^2's.  etc.
Special note: The numbers above 9, in powers above 10, are replaced with letters.  Therefore, A=10, B=11, C=12, etc.
Example: A356 in base 11, to decimal
leftmost: 6.  This is 1's.  So we have decimal 6
next digit: 5.  This is 11^1 = 11's.  So we have 6 + 5*11 = 61
next digit: 3. This is 11^2 = 121's.  Now we have 61 + 3*121 = 424
last digit: A (10).  This is 11^3 = 1331's.  So we get 424 + 10*1331 = 13734 decimal


Now, there are also several shortcuts for certain conversions, which I will outline below.

Decimal -> binary shortcut
Take the decimal number at the top of your page.  Divide by two, keeping the integer result below it and the remainder beside it.  Keep going down the page until you get to 0.  Now the binary number is simply the remainders, taken in order from bottom to top.
Example: decimal 235 to binary
235
117 remainder 1
58 remainder 1
29 remainder 0
14 remainder 1
7 remainder 0
3 remainder 1
1 remainder 1
0 remainder 1
And the final result is the remainders taken in bottom-to-top order, which yields 11101011

Binary -> octal shortcut

1110010101101010 <- random binary number produced by hitting the 1 and 0 keys at random

Octal conversion:
1 / 110 / 010 / 101 / 101 / 010 <- the same number divided into groups of three.  Now convert each group of three into its equivalent.
1 -> 1
110 -> 6
010 -> 2
101 -> 5
010 -> 2

Therefore, octal = 16252

binary-> hexadecimal (base 16) shortcut
basically the same thing, only divide into groups of four instead.
1110 / 0101 / 0110 / 1010
1110 -> 14 = E
0101 -> 5
0110 -> 6
1010 -> 10 = A

Therefore, hex = E56A

octal or hex-> binary.
This is really easy.  Just take the digits and turn them back into groups of three or four binary digits.  (remember, those leading zeros are important.  Don't take them out except on the very leftmost digit :p)

Also, once you've mastered the shortcuts above, converting from octal to hexadecimal is easier if you don't try to go back to decimal, but rather go back to binary instead.

Hope that rather long-winded post helped things.
"We have plenty of youth, how about a fountain of smart?"

February 15, 2004, 11:57:42 PM
Reply #4

Sancho

  • Legacy Admin
  • Fade

  • Offline
  • **

  • 473
    • View Profile
    • http://
Yeah, jhunz pretty much got the jist of it.

Easiest way is to convert the number to decimal, and then to the type you want, but there are shortcuts that he already pointed out.