At 03:42 PM 11/21/98 +0000, you wrote:
>Sure, technically the 2nd century would start only in the year 101,
>and the 21st century in 2001, but who cares? That's just a matter of
>convention. If everyone feels a next century started when 19xx
>changed to 20xx, then it did, didn't it?
It is caused by a common "misunderstanding" that counting starts at 1. I
think that counting from 0 is much nicer and also more practical.
Let me give some other examples:
You want to calculate the memory address of an array element. If your array
has index range [1..N], the memory address of an element would be:
base + (i - 1) * s
where s is the size of one element in bytes.
But if you start counting from zero, the formula would be simpler:
base + i * s
You want to make a menu in which there is a "wrap around": if your cursor
is on the first element and you move backwards, your cursor will move to
the last element. If your elements are numbered [1..N], the code for
moveing the cursor backwards from position "pos" would be like this:
pos := ((pos - 2 + N) mod N) + 1
But if you start counting from 0, it would be like this:
pos := (pos - 1 + N) mod N
(You might wonder why I put "+ N" there. Most programming languages seem to
have the strange convention that -1 mod 4 = 1, instead of 3. Adding N makes
sure the number is never negative, avoiding such problems.)
I could go on for some time, but hopefully you get my message that starting
counting from 0 is more practical, especially when programming.
By the way, although in "real life" most things are (unfortunately)
numbered from 1, building stories are numbered from 0. But somehow floor
zero is given a special name (ground floor or something like that).
Bye,
Maarten
****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****