Subscribe to NeoTifa's Blog of |)00M!!!!        RSS Feed
-----

Tutorial: Number Systems for Beginners

Icon 3 Comments
Number Systems for Beginners by NeoTifa

~~~~~~~~~~~~~~Index~~~~~~~~~~~~~~~~

Part 1.) Introduction
Part 2.) Binary to Decimal
Part 3.) Decimal to Binary
Part 4.) Binary to Octal
Part 5.) Octal to Binary
Part 6.) Binary to Hexadecimal
Part 7.) Hexadecimal to Binary

~~~~~~~~~~~~~Part 1~~~~~~~~~~~~~~~~~~
Introduction:

Hi, thanks for reading my tutorial. This is my first non-Java one, so bear with me. I think binary is a very important concept when it comes to computer programming, and yet a lot of people do not know anything about binary. Therefore, I’m going to sit down and bust this out for your benefit. Just kidding, this is helping me study for my Digital Circuits exam! ;)

A computer is a system of wires and logic gates that computes anything. It can be as complex as the Dell or Apple computer on your desk, or as simple as a pocket calculator. It’s a compute-er, get it? Back in the day, the wrinkly old scientists needed some quicker way to compute complex equations for their evil science, so they used science to discover that electricity can be manipulated logically to form equations. Unfortunately, you’ll notice that your light switch can only have 2 different states: on and off. This is the same limitation said crusty old guys found, so they use gates to manipulate the current to do their evil bidding.

As for the logic, I might do another tutorial on that later, but for the purpose of this tutorial, we’re going to focus on those 2 states: on and off. Since a computer is just an assembly of electrical components, like your light switch, there are really only 2 states that the computer can register: on and off. There are also other ways to represent it: high/low, 1/0, on/off, true/false, etc. Humans took the 1/0 representation and ran with it. We call it binary. Any number can be represented as a series of 1’s and 0’s, and I’m going to show you how!

”Fry! I had the most horrible nightmare! 1’s and 0’s everywhere! I think I even saw a 2!” -Bender

~~~~~~~~~~~~~~~~~Part 2~~~~~~~~~~~~~~~~~~
Binary to Decimal:

Decimal: The number system we puny humans are most familiar with.
Base: 10
Coefficients: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Weight: Power of 10
Notation: (10573406)10

Binary: Series of 1’s and 0’s that a computer is most familiar
Base: 2
Coefficients: 0, 1
Weight: Power of 2
Notation: (10100101101)2

A binary number can be small or large, and can even have decimal points! Each one or zero is called a bit. When someone says their system is a 64-bit system, it means it can process calculations with sequences containing 64 different 1’s and 0’s. The number 7, or 111, has 3 bits; the number 3, 11, has 2 bits. Every place in the string of 1’s and 0’s is 2 to the nth power, with n being the index. All you need to find the decimal equivalent is to take the ones and add them. Just start at the right-most bit (to the left of the decimal point if applicable), which is also called the least significant bit, and add starting with 2^0.
bit(n)*2^(n) + bit(n-1)*2^(n-1) + bit(n-2)*2^(n-2) + ... + bit(2)*2^(2) + bit(1)*2^(1) + bit(0)*2^(0) = Decimal Integer

Here are some examples:
0 = 0
1 = 1
11 = 2^1 + 2^0 = 2 + 1 = 3
111 = 2^2 + 2^1 + 2^0 = 4 + 2 + 1 = 7
10101 = 2^4 + 2^2 + 2^0 = 16 + 4 + 1 = 21

Notice how I skipped 2^3 and 2^1 above? This is because there are 0’s in those places, and because the coefficient would be zero, resulting in 0*2 = 0, it’s unnecessary to compute that. It would be useful to know the powers of 2 off hand, but it’s not necessary.

1024 = 2^10
512 = 2^9
256 = 2^8
128 = 2^7
64 = 2^6
32 = 2^5
16 = 2^4
8 = 2^3
4 = 2^2
2 = 2^1
1 = 2^0

Now for decimal points, you add fractions, or 2 to negative exponents.

... 2^(2) + 2^(1) + 2^(0) + 2^(-1) + 2^(-2)....

Really, you’re just moving across the number line! (Make sure you’re starting at zero right at the decimal point though!)
1.1 = 1.5
1.11 = 1.75
etc.

~~~~~~~~~~~~~~~Part 3~~~~~~~~~~~~~~~
Decimal to Binary:

Going backwards is fairly easy as well. In fact, there are 2 main ways to do it.

1st Method:
If you know the 2’s powers, just subtract the largest possible one that is smaller than or equal to the number you’re trying to convert. This will be your first place for a one. If the 2’s power below it can’t be subtracted (i.e. it’s larger than) the difference, than a zero will go into that place. Just repeat until you’ve reached zero!
500: 500 – 256 = 244 therefore 2^8 = 1
244 – 128 = 116 therefore 2^7 = 1
116 – 64 = 52 therefore 2^6 = 1
52 – 32 = 20 therefore 2^5 = 1
20 – 16 = 4 therefore 2^4 = 1
4 – 4 = 0, therefore 2^3 = 0, 2^2 = 1, 2^1 = 0, and 2^0 = 0, giving us 111110100.
Easy, no?

2nd Method:
This one’s just as easy. Just divide by 2 until you reach 0, and the remainder is the binary bit value. This method give the binary started at the least significant bit!!!
500:
500 / 2 = 250 (r: 0)
250 / 2 = 125 (r: 0)
125 / 2 = 62 (r: 1)
62 / 2 = 31 (r: 0)
31 / 2 = 15 (r: 1)
15 / 2 = 7 (r: 1)
7 / 2 = 3 (r: 1)
3 / 2 = 1 (r: 1)
1 / 2 = 0 (r: 1) ... thus giving us 111110100.

~~~~~~~~~~~~~Part 4~~~~~~~~~~~~
Binary to Octal:

Octal: A human system that counts in 8’s. Why? Idk.
Base: 8
Coefficients: 0, 1, 2, 3, 4, 5, 6, 7
Weight: Power of 8
Notation: (35157351)8

Octal is kind of a mix between binary and decimal, sort of easy for humans, but it reads in 8^n + 8^n-1 etc. The max number in each place can be 7, which is 111. Therefore, every 3 bits is an octal number. To convert from binary to octal, just start from the decimal point, and group outwards every 3 bits. If there is a leftover, or the number of bits isn’t divisible by 3, just pad it with 0’s until it is 3 bits. The reason why it can’t be 8 (1000) is because 8 is 4 bits, and then you would just pad it with 0’s, turning 1000 into 10 in octal.

For instance 11111.1, you would divide and pad them as such: 011 111.100. This is generally why there are spaces in binary numbers, as sometimes the coder spaces them for you. ;) Each grouping is then converted into its appropriate octal number. Also, instead of adding fractions, just convert it as if it were just a regular number to the left of the decimal.
011 = 3, 111 = 7, 100 = 4
Therefore, (11111.1)2 = (37.4)8

~~~~~~~~~~~~Part 5~~~~~~~~~~~~
Octal to Binary:

Super easy! Just take each index, or place, and convert it into a [padded if necessary] 3 bit number! Taking the padding back out from the ends is optional.

Ex.
2534 = 010 101 011 100
435.5 = 100 011 101.101

In fact, when I do binary stuff, I like to remember the truth tables I did in math.
ABC – 3-bits
---------------------------
000 - 0
001 - 1
010 - 2
011 - 3
100 - 4
101 - 5
110 - 6
111 - 7


See, there’s a pattern, so if you keep this in your mental database you can remember them easier. ;)

~~~~~~~~~~~~~~~~Part 6~~~~~~~~~~~~~~~~
Binary to Hexadecimal:

Hexadecimal: Another human system, popular with the visual kiddies and stuff
Base: 16
Coefficients: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Weight: 16
Notation: (32AD635)16

This one scares people for some reason. They see letters in a number system and freak... or I did at least. Haha, it’s not that hard though. Because 0 and 1 are their own separate numbers, you have to notate 10 – 15 in some other way, so we just use letters. To convert to hex, you do the same thing as octal, but instead of 3 bits it’s 4. Simple enough.

Ex.
10110101011010100.010100111 =
0001 0110 1010 1101 0100.0101 0011 1000 =
1 6 A D 4.5 3 8 =
16AD4.538

ABCD – 4 bits
---------------------------------
0000 – 0
0001 – 1
0010 – 2
0011 – 3
0100 – 4
0101 – 5
0110 – 6
0111 - 7
1000 – 8
1001 – 9
1010 – A
1011 – B
1100 – C
1101 – D
1110 – E
1111 – F



~~~~~~~~~~~~~~~Part 7~~~~~~~~~~~~
Hexadecimal to Binary:

Just like with octal, take each character and convert it to its respective [potentially padded] 4-bit binary number, then take out the padding on both ends [if you added it].
Ex.
3986 =
0011 1001 1000 0110 =
111001100000110

132AD.7 =
0001 0011 0010 1010 1101.0111 =
10011001010101101.0111

In order to convert between different number systems, just use binary as the middle man. So to get from Oct to Hex, just got Oct -> Bin -> Hex. Well, this concludes my tutorial. Hope someone finds it useful. Thanks for reading! ^__^

Attached File(s)

3 Comments On This Entry

Page 1 of 1

NickDMax 

09 June 2010 - 12:23 PM
nice
0

Martyr2 

11 June 2010 - 10:16 PM
This is a pretty nice blog post you have here Neo. I am a bit impressed that you took the time to create something like this and make a solid blog post out of it. Nice work indeed! :^:
0

NeoTifa 

22 June 2010 - 07:25 AM
Thank you! ^__^ I also submitted it as a tutorial. :P
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

March 2021

S M T W T F S
 123 4 56
78910111213
14151617181920
21222324252627
28293031   

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)