Sie sind auf Seite 1von 6

The Basics of Bases v1.

The Romhacking dot Net Version
written by Neil_
Originally Written 10/19/01
Last Revised on 12/5/05

So you want to be a ROM Hacker? Now's a great time to learn. We're at what is mo
likely the tail end of the SNES hacking era. Things are only going to get more
complicated from here. If you intend on getting in on the fun the 32 bit era
promises, learning the 16 bit basics now would probably be a good idea.

-The Basics of BasesQ. How many fingers is the normal human child born with?
A. 10.
Q. How many fingers is your computer born with?
A. uh.... ?

Believe it or not, your computer does not count with the same number system you
Neither do game consoles. Unless you're in posession of a Setun computer or some
such, your computer counts using two numbers, 0 and 1. On and Off. This my frien
is called the Binary Number System. You will NEED to know how to convert between
binary, decimal and a third numbering system (hexadecimal) if you intend on gett
down and dirty in some hot and heavy hacking action.

-So how does this mysterious numbering system work?

It's easy as pie my friends.
Do you remember in grade school going over the difference between the ones, tens
and hundreds place in math class? They'd draw these little boxes to help you cou
and identify how many hundreds there were in 347.




| 3 |

| 4 |

| 7 |

----Hundreds Tens


This was an important concept to gather back in first grade. The idea that by
changing the place of numbers in a string, you'd completely change the value of
individual numbers and the entire string. 347 has a different meaning than 743 o
734 or 437 even though it contains the same numbers. It's a concept that you pr
take for granted these days.
Binary works the same way. You've got different places, and the places matter. B
time. Just like you can't reorder 347 to 437 and have it be the same number, yo
can't just move around binary numbers and have them hold the same meaning.
Lets look
at the decimal number 205 in binary (11001101).

1 0 0 1 1 0 1
\ \ \ | | / / /
128 64 32 16 8 4 2 1

As the above diagram shows, 8 binary digits are used to represent the number 205
The binary digits, just like the decimal numbers you're used to, go from left to
right with the digit with the greatest value to the left and the smallest value
the right.
This brings us to an important exercise. How exactly do you convert between deci
and binary?

Well, first off, lets go from binary to decimal. Once again, lets refer to the
diagram above. 11001101. As the diagram shows, each of those binary "bits" or d
equates to a decimal number. The value to the far left equates to 128 or 2 raise
d to
the 7th power in exponential notation. In fact, each of those binary digits equa
to a power of 2. That's why it's called the "Binary" system. Bi being a prefix
meaning 2 (Dec coincidentally is the prefix for 10 even though December is the
month of the year. For this we have a bunch of pompus Roman Emperors to thank. Y

Augustus and Julius!).

In any case, to convert binary numbers to decimal numbers, we
work from the right to the left, multiplying the binary digit by a power of 2.
Here's how it works out in this case:

Now we add the numbers together.


What a suprise! 205. Who would have predicted that number would result from
string of binary bits! Now how do we convert 205 back into binary? What wou
in binary even look like? Pretend like you don't know the answer. It's more

To figure out the binary representation of a decimal number, we're going to have
to divide by 2 until we hit 0, paying particular attention to remainders and
ignoring any numbers after the decimal place that result from our division, as s

205/2=102 remainder 1
102/2=51 remainder 0
51/2=25 remainder 1
25/2=12 remainder 1
12/2=6 remainder 0
6/2=3 remainder 0
3/2=1 remainder 1

1/2=0 remainder 1

Now we read the remainders from the bottom of the list to the top and write them
left to right, as such:
Low and behold, we're back where we started!

-Moving Up-

"Well, what about hexadecimal," you ask "I always hear some random loser romhack
talking about hexadecimal. How does that work?"
Hexadecimal is rather easy. Before we get into converting back and forth between
decimal and hex, let me introduce you to the new way of counting. Ever hear of
math? This is nothing like that.
0 1 2 3 4 5 6 7 8 9 A B C D E F.
Those right there are your new numbers. Learn them well and never forget them.
try and count in hexadecimal up to 30 and watch the progression of numbers:

0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E

Well now. That wasn't too hard, was it. What? You don't believe me that 1E is 30
(even if you do, please play along. It makes this so much more fun)? Lets conver
t 1E
to decimal and find out. Converting hexadecimal to decimal is done pretty much
same way converting binary to hexadecimal was done.

The digit on the far right is said to be in the "0's place" and the digit to th
left of the 0 is in the "1's place". Just like we did with the binary conversio
we're going to be multiplying by a power of some number. What would that number
here? In the case of binary (base 2) it was 2. So in the case of hexadecimal (b

16), I suppose it would be 16, ne?

E * 16^0
1 * 16^1
E is the hexadecimal equivalent of 14. (A=10, B=11, C=12, ...)
Keep in mind the
lessons from your highschool math lessons. Anything to the 0 power is 1. And
anything to the 1st power is itself. Therefore 16 raised to the 0 power is equal
1, and 16 raised to the first power is 16.
That gets us this far:


Now we add up our results. 16 + 14 = 30. Tada. Ladies and gentlemen, we have jus
converted a hexadecimal number to decimal! Yay for us.
Ok. How about the other way around. How would I convert a decimal number to
hexadecimal? How about we try that division stuff that worked so well before for
binary? Sounds like a plan to me. Lets try again with 30.

30/16=1 Remainder 14
1/16=0 Remainder 1

Now we read from the bottom up, remembering to convert remainders larger than 9
their Hexadecimal digit equivalents. So we've got 1 and 14 which is E. 1E. Yay.
Another successful conversion!
At this point, all you really need is practice. I'd suggest taking the time to
some conversions on a piece of paper and testing yourself with a scientific
calculator. Windows has one built in. Good ol' Calc can be turned into scientifi
mode and will gladly convert numbers between bases for you. With a little practi
you should be able to do simple conversions in your head, or at least be able to
ballpark a conversion in your head. Good luck and welcome to the world of rom