-
May 27th, 2003, 09:33 PM
#1
Computers and Numbering Systems Part 1 - Decimal and Binary
Overview
This is a 3 part tutorial. Part 1 covers the decimal and binary numbering systems, part 2 covers the hexadecimal numbering system, and part 3 is an overview on how computers manage numbers.
Decimal(base-10)
Decimal(base-10) is the everyday numbering system that you are used to. It has the symbols:
0,1,2,3,4,5,6,7,8,9
Now, notice the base-10 in the parenthesises above? Notice how many symbols are in the decimal system(10)? A numbering systems base is the amount of symbols in the numbering system. For decimal, the number of symbols is 10. With those ten symbols we add, subtract, multiply, divide, and a dozen other things.
Let's break down a decimal number. Say, 280. When we break down the number we get:
2*(10)^2 + 8*(10)^1 + 0*(10)^0
once simplified:
200+80+0=280
(remember that zero to any power is 1 and any number times 0 is 0)
Notice that in each case, we multiply by a power of 10.
Binary(base-2)
Binary(base-2) is the numbering system that computers use. If you read the above explination of bases then you know that binary(base-2) only has two symbols:
0,1
And yes, we can make any whole number(0,1,2,3,...) that we want with just two symbols. Below is a chart that shows a binary number on the left and what it is in decimal on the right:
Binary Decimal
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
10001 17
11110 30
1000010 66
Now you're probably thinking, "why do would computers use a numbering system whose numbers are so long(like 1000010 instead of the short decimal 66)?"
The answer? Computers represent the 0 or 1 with electricity. Say, +5 volts for 1 and 0 volts for 0. If a computer used the decimal numbering system, then it would need ten different voltages and much more complex and expensive hardware.
Converting Binary to Decimal
Converting a binary number to a decimal number is very easy. All we need to do is multiply each digit in the binary number by the correct power of 2. The correct power of 2 is easily found by counting the number of digits to the digit that you want and subtracting one.
So, let's convert 10101 to decimal:
1*(2)^4 + 0*(2)^3 + 1*(2)^2 + 0*(2)^1 + 1*(2)^0
once simplified:
16+0+4+0+1=21
Here are some more examples:
Binary: 10
1*(2)^1 + 0*(2)^0
once simplified
2+0=2
Binary: 101
1*(2)^2 + 0*(2)^1 + 1*(2)^0
once simplified
4+0+1=5
Binary: 1110011
1*(2)^6 + 1*(2)^5 + 1*(2)^4 + 0*(2)^3 + 0*(2)^2 + 1*(2)^1 + 1*(2)^0
once simplified
64+32+16+0+0+2+1=115
Converting Decimal to Binary
Converting decimal to binary is a little bit harder than binary to decimal. The easiest thing to to is to start by making a table with the powers of 2 like this:
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
Okay, we're going to convert 15(decimal) to binary. To start we need to look at our chart and find the highest power of 2 that we can subtract from 15 without ending up with a negative number. In this case it is 2^3 which is 8. We now know that the binary equivilent of 15 is going to have 4 digits(the exponent + 1 tells us this). So we write down for spaces:
_ _ _ _
In the first place we have a 1 because we are able to subtract 2^3 from 15 with a remainder of positive 7. So we now have:
1_ _ _
We take our remainder of 7 and see if the next lowest power of 2 can be subtracted form 7 without giving us a negative number. In this case the next lowest power of 2 is 2^2 which equals 4. We subtract 4 from 7 and endup with a positive remainder of 3. So our next place in the binary number is 1:
11_ _
We keep doing this until we are left with nothing:
3-2^1=1
111_
1-2^0=0
1111
So 15 equals 1111 binary.
Now, let's convert 5 to binary. We find the highest power of 2 that when subtracted from 5 doesn't give us a negative answer. In this case it is 2^2 which is 4. We now know that we will have 3 digits in our binary number:
_ _ _
We subtract 4 from 5 and have a remainder of positive 1:
1_ _
Now we take the next lowest power of 2. It's 2^1 which equals 2. When we subtract 2 from 1 we end up with -1. What does that mean? It means that the digit for that space in our binary number is 0:
10_
Note that we still have positive 1. Since subtracting 2^1 from 1 would leave us with -1 we don't subtract 2^1 from 1. Now we take the next lowest power of 2, which is 2^0, and subtract it from 1. We are left with an answer of 0. Since 0 isn't negative we set our last digit in our binary number to 1 and we are done:
101
So 15 equals 101 binary
Here are some more examples:
20:
20 - 2^4 = 4
1 _ _ _ _
4 - 2^3 = -4
10_ _ _
4 - 2^2 = 0
101_ _
We're left with 0 so the rest of the digits are 0,
10100
7:
7 - 2^2 = 3
1_ _
3 - 2^1 = 1
11_
1 - 2^0 = 0
111
31:
31 - 2^4 = 15
1_ _ _ _
15 - 2^3 = 7
11_ _ _
7 - 2^2 = 3
111_ _
3 - 2^1 = 1
1111_
1 - 2^0 = 0
11111
Now you should be able to convert binary to decimal and decimal to binary. Part 2 of this tutorial will cover the hexadecimal numbering system.
-
May 27th, 2003, 09:55 PM
#2
source: http://osdev.neopages.net/tutorials/pdf/numbering_1.pdf
**Thread moved from Tutorials to General Chit Chat. Not original tutorial** Please read the Legal Notices.
-
May 27th, 2003, 09:56 PM
#3
You're *fast*, MsMittens
*Moved from Tutorials... *sigh**
-
May 27th, 2003, 11:36 PM
#4
possibly an easier way to convert decimal to binary in two easy steps.
(a) divide by two - if remainder is one, you got a binary 1 as the, if its zero, you got a binary 0 - as your least significant bit.
(b) keep repeating step (a)
Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!
-
May 30th, 2003, 03:20 AM
#5
damnit you didnt mention ettercap, i figured you could have at least came up with a way to do that..
-
May 30th, 2003, 04:24 AM
#6
Originally posted here by (V)/\><
possibly an easier way to convert decimal to binary in two easy steps.
(a) divide by two - if remainder is one, you got a binary 1 as the, if its zero, you got a binary 0 - as your least significant bit.
(b) keep repeating step (a)
The chart is definately easier than dividing. The only people who will tell you to divide to find a binary number are mathematicians because they have their theory then.... other than that.. use the chart.... There's a few tutorials on Number Conversions. I know i posted one and I believe there's another as well.. anyways..... Never divide.. it wastes your time.
-
May 30th, 2003, 02:50 PM
#7
I dont know if the *nix calculators do this but Windows calculator will do this for you automaticaly. it will go between decimal binary and hex and oct. Just got view select scientific enter then number you want to convert and click the apropriate radio buton. The REALLY easy way
-
May 30th, 2003, 04:32 PM
#8
Useualy I do a easy conversion into hex. the hex-binary binary-hex conversion is trivial.
Who is more trustworthy then all of the gurus or Buddha’s?
-
May 31st, 2003, 03:22 AM
#9
The chart is definately easier than dividing. The only people who will tell you to divide to find a binary number are mathematicians because they have their theory then.... other than that.. use the chart.... There's a few tutorials on Number Conversions. I know i posted one and I believe there's another as well.. anyways..... Never divide.. it wastes your time.
i tend to agree with the mathematicians with this one. though the chart may be less time consuming on paper, computers divide better than they look up charts. unless maybe you are using some sort of bucket.
Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!
-
May 31st, 2003, 03:46 AM
#10
Originally posted here by (V)/\><
i tend to agree with the mathematicians with this one. though the chart may be less time consuming on paper, computers divide better than they look up charts. unless maybe you are using some sort of bucket.
I'll agree that a computer can definately divide better than it'll look up things in a chart. However this was for a person to do binary conversions, or at least that's how I presumed it to be. So acting under that assumption, I'd say that the chart is easier for people.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|