Motivation
I Googled for a quick, simple explanation of this and was very surprised when I failed to find one, so here we go. Oh, and the whole puppies thing is a reference to this post.
Bases
The base is just defined by how many characters we have to represent numbers.
- In binary (base two), we use characters 0, 1
- In octal (base eight), we use characters 0, 1, 2, 3, 4, 5, 6, 7
- In decimal (base ten), we use characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- In hexadecimal (base sixteen), we use characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
- zero 00
- one 01
- two 02
- three 03
- four 04
- five 05
- six 06
- seven 07
- eight 08
- nine 09
- ten 10 -- here we start reusing characters...
- eleven 11
- twelve 12
but for binary we only have two characters with which to represent puppies, so we have to move over a lot quicker:
- zero 000
- one 001
- two 010 -- quickly we start reusing characters...
- three 011
- four 100
- five 101
- six 110
similarly for octal, we count:
- zero 00
- one 01
- two 02
- three 03
- four 04
- five 05
- six 06
- seven 07
- eight 10 -- here we start reusing characters...
- nine 11
- ten 12
and finally, for hexadecimal, we have to "make up" some extra characters that we're not used to (since most humans are used to the decimal, or base 10, system), so someone long ago chose the letters A-F:
- zero 00
- one 01
- two 02
- three 03
- four 04
- five 05
- six 06
- seven 07
- eight 08
- nine 09
- ten 0A
- eleven 0B
- twelve 0C
- thirteen 0D
- fourteen 0E
- fifteen 0F
- sixteen 10 -- finally we start reusing characters...
- seventeen 11
- eighteen 12
Hexadecimal can be a little weird to think about but try thinking about it this way: if someone created five hundred unique characters that we used to count things, we could just point to a herd of, for example, four hundred and eighty puppies in a park, and you could use a single character to represent that number. That character would uniquely identify the number of puppies you see sniffing and playing and rolling in the dirt. My guess is that you would spontaneously explode from how cute it was.
A generic formula for figuring out what a number means in your base
So "432" in decimal:
- ten * ten * four +
- ten * three +
- two =
- Four hundred and thirty two
"432" Octal:
- eight * eight * four +
- eight * three +
- two =
- Two hundred and eighty two
"2BC" Hex:
- sixteen * sixteen * two +
- sixteen * eleven +
- twelve =
- Seven hundred
"1101" Binary:
- two * two * two * one +
- two * two * one +
- two * zero +
- one =
- Thirteen
The formula can also be expressed as "the base raised to the power of the number of times you've had to "move over a spot." It's just the same. For example:
"432" in decimal:
- ten to the second power * four +
- ten to the first power * three +
- ten to the zeroth power * two =
- Four hundred and thirty two
No comments:
Post a Comment