• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What's up with zero indexing?

Chaotic42

Lifer
I don't understand it. Why is my first hard drive (hd0)? Why do some arrays call the first useful entry [0]? Why is my first CD drive scd0?

Counting starts at 1. I've never seen anyone, outside of the computing industry, write 0 as the first number. I've also never seen anyone count using 0 as the first number.

***

That's not 2 asterisks, it's 3. The last one is the third, not the second.

Just curious, as it doesn't make much sense to me.
 
I've never seen anyone, outside of the computing industry, write 0 as the first number.

Well this is IN the computer industry! I don't know the exact reason for starting at zero, but it makes sense. I guess it's just a matter of tradition. BTW, in linux, it's hda1, hda2, etc for hard drives, what is hd0?
 
Because 0000 = 1 didn't make any sense.

let's say I want to represent 4 options:

00
01
10
11

Looks nice, I get away with only using 2 bits.

Now, what if we don't start at 0?
01
10
11

Uh oh, I ran out of options, so to represent 4 options without using 00, I need:
001
010
011
100

I just wasted a bit because I didn't use a potential option. Wasteful programming wasn't always an option like it is now. There was a point where using only the absolute minimum number of bits was what was needed. Hence all the logic foundations start at 0.
 
If you didn't start counting at zero, how could you have 0-day warez? 😉

Like Kilrsat said, you don't waste a value of zero. It's a big factor in why so many programming bugs are "off-by-one" errors.
 
It comes from doing pointer math.

Lets say you have an array of 10 ints in C, called x.

The memory location pointed to by x is your first array element. This is *(x+0) or x[0]
If this was referred to as x[1], the nice tricks where you can add to a pointer to change the index you're looking at wouldn't make sense.
x[5] is worked out by adding 5*sizeof(int) to pointer x and dereferencing it. If x[5] was the 5th element rather than the 6th, it would instead need to be evaluated by adding (5-1)*sizeof(int) to x then dereferencing. Rather than having to subtract 1 to correct the calculated addresses of array elements the arrays start at 0 instead of 1.

I know the above isn't exactly clear, can't figure out how to word it better right now.
 
The threshold of a given number base is always the base- 1. In other words, the maximum value for a single digit in base 10 in 9, 1 for base 2, etc.. The first digit is of course 0. If you started at 1, you wouldn't be able to permute enough representations for the entire base. If you have a base 5 and started at 1, you'd have a max value of 6. That doesn't make much sense, does it?

It's the same thing with indexes.
 
Originally posted by: BingBongWongFooey
I've never seen anyone, outside of the computing industry, write 0 as the first number.

Well this is IN the computer industry! I don't know the exact reason for starting at zero, but it makes sense. I guess it's just a matter of tradition. BTW, in linux, it's hda1, hda2, etc for hard drives, what is hd0?

hd0 is GRUB's name for my first hard drive.

Reading through the other posts, I see now why they start at 0. Thanks guys!
 
Back
Top