Why does almost everything in programming have to do with a multiple of 2? Just wondering.
Multiples of 2...
Miscellaneous Forums/General Discussion/Multiples of 2... because when you add another channel on a circuit board it does more than add 1, because of the way binary works every channel added is worth double the previous total quantity.
That's why 24bit graphics are 16,777,216 colours, because if you double 24 times thats what you get.
^2
That's why 24bit graphics are 16,777,216 colours, because if you double 24 times thats what you get.
^2
logic gates within microprocessor working as 'switchers' open or close, in another words 1 or 0 what representing two stages and everything else is based on that..
You're programming on a Binary Computer. In a binary system, an (unsigned) integer is represented by a series of bits (1s and 0s), making the range of numbers which can be represented 0..2^bits.
The reason that computers are binary is that it's relatively easy to design circuits and logic that only deals with two values. For contrast see the Wikipedia article on Ternary computers and relevant links.
The reason that computers are binary is that it's relatively easy to design circuits and logic that only deals with two values. For contrast see the Wikipedia article on Ternary computers and relevant links.
It's quite simple really.
Computers work in terms of yes and no, which translates to 0 and 1.
When you get right down the the hardware, all you have are a bunch of logic gates. These are tiny electronic things that when you apply a current to one prong that means 1, and when you don't, that means 0. These have two prongs in, and one prong out and give results like:
AND:
1 + 0 = 0
1 + 1 = 1
OR:
1 + 0 = 1
1 + 1 = 1
Now that you know that, you should understand why the computer deals with 0's and 1's. But it's not just for that reason they use 0's and 1's. They use 0's and 1's because that is the simplest number system you can have.
Our normal number system is base 10. That means that there are 10 digits, 0 through 9, so when we count, when we hit 09, adding one more means we have to loop back to 0 and increment the next digit, so we get 10.
Binary is base 2. (You can't have base 1) So when you hit 1, you wrap it to 0 and increment the next digit, so you go:
00
01
10
Another reason computers use binary is because MEMORY is binary. You don't have bytes when you get down to the hardware level, you might have switches. And those switches can be opened or closed. 0, or 1. So again we get back to binary.
Now why is everyhting a multiple of 2? Well, if we convert from binary to decimal we get our answer:
0000 = 0
0001 = 1 !
0010 = 2 !
0011 = 3
0100 = 4 !
0101 = 5
0110 = 6
0111 = 7
1000 = 8 !
Do you see a pattern? Wherever I put a ! is a POWER of 2, (not amultiple of 2) and at those points only ONE bit is set. That particular bit therefore has that value. If I add 1+2+4, each of which has a single bit set in binary, (1, 10, 100), then I get 7, which is 111 in binary.
So it all works out.
And they are powers of 2, not multiples of 2. Six is a multiple of 2. Six is 2*3. But six is not a power of 2. A power of 2 is 2^N where N is some number.
2^0 = 1 (Don't ask me why, I don't know, but it's the answer we want for this when working in binary which is convenient!)
2^1 = 2
2^2 = 2*2 = 4
2^3 = 2*2*2 = 8
2^4 = 2*2*2*2 = 16
As you can see, exponents provide a nice way to get those powers of 2, and the exponent you use, tells you which bit will be set for that number!
I think that about covers your question. :-)
Computers work in terms of yes and no, which translates to 0 and 1.
When you get right down the the hardware, all you have are a bunch of logic gates. These are tiny electronic things that when you apply a current to one prong that means 1, and when you don't, that means 0. These have two prongs in, and one prong out and give results like:
AND:
1 + 0 = 0
1 + 1 = 1
OR:
1 + 0 = 1
1 + 1 = 1
Now that you know that, you should understand why the computer deals with 0's and 1's. But it's not just for that reason they use 0's and 1's. They use 0's and 1's because that is the simplest number system you can have.
Our normal number system is base 10. That means that there are 10 digits, 0 through 9, so when we count, when we hit 09, adding one more means we have to loop back to 0 and increment the next digit, so we get 10.
Binary is base 2. (You can't have base 1) So when you hit 1, you wrap it to 0 and increment the next digit, so you go:
00
01
10
Another reason computers use binary is because MEMORY is binary. You don't have bytes when you get down to the hardware level, you might have switches. And those switches can be opened or closed. 0, or 1. So again we get back to binary.
Now why is everyhting a multiple of 2? Well, if we convert from binary to decimal we get our answer:
0000 = 0
0001 = 1 !
0010 = 2 !
0011 = 3
0100 = 4 !
0101 = 5
0110 = 6
0111 = 7
1000 = 8 !
Do you see a pattern? Wherever I put a ! is a POWER of 2, (not amultiple of 2) and at those points only ONE bit is set. That particular bit therefore has that value. If I add 1+2+4, each of which has a single bit set in binary, (1, 10, 100), then I get 7, which is 111 in binary.
So it all works out.
And they are powers of 2, not multiples of 2. Six is a multiple of 2. Six is 2*3. But six is not a power of 2. A power of 2 is 2^N where N is some number.
2^0 = 1 (Don't ask me why, I don't know, but it's the answer we want for this when working in binary which is convenient!)
2^1 = 2
2^2 = 2*2 = 4
2^3 = 2*2*2 = 8
2^4 = 2*2*2*2 = 16
As you can see, exponents provide a nice way to get those powers of 2, and the exponent you use, tells you which bit will be set for that number!
I think that about covers your question. :-)
Why does almost everything in programming have to do with a multiple of 2?
They don't. They have to be exponents (?) of 2, i.e. 2^n where n is the number of bits you have at your disposal.Also check out the Wikipedia article on Finite State Machines.
But... truly... there is no such number as 0 (zed) in infinite math... you never reach zero.
Topology is simple: If I have 1 apple and I give you 1 apple then I have -1 apples. I do not have 0 apples since 0 does not truly exist.
Topology is simple: If I have 1 apple and I give you 1 apple then I have -1 apples. I do not have 0 apples since 0 does not truly exist.
@Rook: I always said there was something fundamentally wrong with the universe.
If I have 1 apple and I give you 1 apple then I have -1 apples
Oooh! Can i have one of the new Macs with the six button remote that does more than a 46 button Media centre beast. You're a mate RZ !
Thing is if you turn up to a meeting with no apples, you don't have -1 apples, you have none.
Even if you give away your only apple, you can never have less than nothing. That's just silly. I don't care if nothing doesn't exist, you can't have less than it.
And then he goes on with the longest reply in the thread. =]
Last but not least, the original poster has a cool nick.
It's quite simple really.
And then he goes on with the longest reply in the thread. =]
Last but not least, the original poster has a cool nick.
Topology is simple: If I have 1 apple and I give you 1 apple then I have -1 apples.
Are you certain? Surely when you had one apple then you had -(all_the_apples_in_existence - 1), and when you gave that apple to me (cheers) you then had -(all_the_apples_in_existence)? We need to get to the core of this.
I'd advise against that. All you'll find at the core will be poisonous seeds.
just because.
One of the cleverest inventions came from ancient india, where they invented the number zero.
They had to invent the concept of zero to advance mathematics.
They had to invent the concept of zero to advance mathematics.
Taht's right then it made tha arabic numbering system viable.