Tuesday, 13 September 2011

Converting between Number Systems

I'm finally back from an extensive summer of military training. I am finally back in school. So now I can go back to blogging and teaching what I am currently learning. Both so you as the reader can learn some neat things; and I can remember what was taught. Call it studying maybe. So one of my computer science classes is "Intro to Computer Architecture". First day I learned to convert between 4 number systems.

I won't go into much detail about what exactly they are. But here they are.

Decimal: Can use any number between 0 and 9.

Hexadecimal: Can use any number between 0 and 9. Any number higher is represented by a letter. These letters are A to F. Where A = 10 and F = 15.

Octal: Can use any number between 0 to 7.

Decimal: Can use 0 or 1.

One thing i will mention which is important is these number systems use a base.

Denoted as (N)^what ever base

Decimal is base 10.  (N)^10

Hexadecimal is base  16. (N)^16

Octal is base 8. (N)^8

Binary is base 2. (N)^2


The base is represented by how many numbers are in the number systems set.

So as for converting between the numbers.

EX Decimal to Binary

Lets have our decimal number as 1411 as today is the 14th and the year is 2011.

So we write (1411)^10 ---> (N)^2   to show our decimal number and what base we are converting to.

Heres where the conversion starts. Take whatever the base is of the system you are converting two. Then divide the number you are converting by that base. Keeping the remainder each time and add it on top of your divided number. We are actually using the operator Modulo instead.

1411 / 2 = 705+1
705/2 =  352+1
352/ 2 =  176 + 0
176/2 = 88 + 0
88/2 = 44 + 0
44/2 = 22 + 0
22/2 = 11 + 0
11/2 = 5 + 1
5 / 2 = 2 + 1
2 / 2 = 1 + 0
1 / 2 = 0 + 1

When we get to zero as in bold above we stop. Note that this is also similar to Euclid's algorithm. Now this is the kool part. Starting from the bottom of that long series of modulo. Take the remainders of each modulo and write those numbers next to each other as shown below.

(10110000011) this is the binary conversion. To test to see if we did this right. Starting from the right hand side of our binary number. We go up the powers of 2 on each number.

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

So to break our binary up into individual bits.starting from the right hand side. If it is a one you give it the power of two determined.

1 + 2 + 128 + 256 + 1024 = 1411.

EX conversion from octal to binary.

This starts to get a little different. Octal has a base of 8. Which means that for each octal number binary requires 3 binary numbers.

Lets pick good old 63.

(63)^ 8 ---> (N)^2. Same idea but now we do each number individually. So starting at 6 then 3.

6/2 = 3 + 0
3/2 = 1 + 1
1=2 = 0 + 1    if you notice there is our 3 binary numbers required to represent one octal number.


3/2 = 1 + 1
1/2 = 0 + 1

Now in this case if you start with zero. But you know you have to have 3 numbers keep going till you have three numbers.

3/2 = 1 + 1
1/2 = 0 + 1
0 / 2 = 0 + 0 

So taking our 6 binary numbers. we get (110) and (011)

Testing this out to see if we did it correctly.
(110) = 2+4 = 6
(011) = 1+ 2 = 3

Note that testing the two together will give you 51 and not 63. By together I mean 110011.

Hexadecimal to Octal

(FACE5) ^ 16 ---> (N)^8

For these conversion we either need to change hexadecimal to binary or decimal. If you change to binary for each hexadecimal requires 4 bits( 4 binary numbers, such as how octal requires 3 bits).

We will convert to binary.

(FACE5)^16 ---> (N)^ 2

F = 15 / 2 = 7 + 1
7 / 2 = 3 + 1
3 / 2 = 1 + 1
1 / 2 = 0 + 1

A = 10 / 2 = 5 + 0
5 / 2 = 2 + 1
2/2 = 1 + 0
1/2 = 0 + 1

C = 12 / 2 = 6 + 0
6 = 2 = 3 + 0
3 / 2 = 1 + 1
1/2 = 0 + 1

E = 14 / 2 = 7 + 0
7 / 2 = 3 + 1
3 / 2  = 1 + 1
1/2 = 0 + 1

5/2 = 2 + 1
2/2 = 1 + 0
1/ 2 = 0 + 1
0 / 2 = 0 + 0

Our binary conversion is (1111101011100101) Now becuase octal takes 3 bits per number we need to split our binary up into groups of 3 bits.

Since theres 16/ 3 =  5  Remainder 1 Let the one remainder be the first bit. The group the rest.

1  111 101 011 100 101. Now lets see what are octal number is.


101 = 1 + 4 = 5
100 = 4
011 = 1 + 2 = 3
101 = 5
111 = 1 + 2 + 4 = 7
1 = 1

175345

Hope you had fun reading this. Have fun showing off to friends.





 

11 comments:

  1. this looks suspiciously like my old homework.

    ReplyDelete
  2. Thanks for the tips, could be useful

    ReplyDelete
  3. looks kind of hard at first, but that's pretty easy.

    ReplyDelete
  4. what odis said :3
    ... following :D

    ReplyDelete
  5. Well done. You need to update your blog however.

    ReplyDelete
  6. When do you use these numbers systems, DiposedCheese?

    ReplyDelete
  7. Undeniably believe that which you said. Your favorite justification appeared to be on the web the easiest thing to be aware of.
    I say to you, I certainly get annoyed while
    people consider worries that they just do not know
    about. You managed to hit the nail upon the top and defined out the whole thing without having side
    effect , people could take a signal. Will probably be back to get more.
    Thanks

    Also visit my website :: nyse penny stocks

    ReplyDelete
  8. Hey! I just wanted to ask if you ever have any problems with hackers?

    My last blog (wordpress) was hacked and I ended up losing a few
    months of hard work due to no back up. Do you have any methods to prevent hackers?



    Feel free to surf to my web-site :: trade penny stocks

    ReplyDelete
  9. You have a really great site! I love how useful a lot of your topics are. I was wondering if you would consider mentioning my website on your next post? I’ll be sure to mention yours on my blog in return. Thanks!

    Sage
    sage.harman123 at gmail.com

    smartphone

    ReplyDelete
  10. Hey, I had a great time reading your website. Can I contact you through email?. Please email me back.

    Regards,

    Angela
    angelabrooks741 gmail.com

    ReplyDelete