Welcome to the new Independent website. We hope you enjoy it and we value your feedback. Please contact us here.


A-Z of the digital world

Z is for Zeroth. With a neat circularity that should please the true hacker - the last item in our catalogue means "first". For software designers working in C and the artificial intelligence language Lisp, the first item in a list is always the "zeroth" (zee-rowth). Hardware people also tend to start counting at 0 instead of 1 - a natural result of the fact that the 256 states of 8 bits correspond to the binary numbers 0, 1, ..., 255 and the digital devices known as "counters" count in this way.

Hackers and computer scientists, unwilling to let their obsessions remain computer-based, often like to call the first chapter of a publication "Chapter 0", especially if it is of an introductory nature: one of the classic instances was in the first edition of Brian Kernighan and Dennis Ritchie's book The C Programming Language. In recent years this trait has also been observed among many pure mathematicians (who have an independent tradition of numbering from 0, and getting into fights after a few beers in bars over what sort of integer zero is).

Zero-based numbering does actually have real usefulness: it reduces the likelihood of "fencepost errors", which can easily occur in programs that repeat a calculation until some boundary condition is true - that is, perform an "iterative loop".

Fencepost errors are so named from the problem known to settlers in the Wild West: how many posts are needed to build a fence 10 metres long with 1 metre between each post? (Clue: the answer is not 10.) Or suppose you have a long list of items, and want to process items m through n: how many items are there to process? The obvious answer is n-m, but that is off by one; the right answer is (n-m+1). A program that used the "obvious" formula would have a fencepost error in it. However, if you rest the list of items to be processed into an array that started numbering at 0, you wouldn't. Which is why sometimes it's better to be zeroth than first.