Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question was posted over a year ago, but here goes...</p> <hr> <h3>About the above reasons</h3> <p>While <a href="http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF" rel="noreferrer">Dijkstra's article</a> (previously referenced in a now-deleted <a href="https://stackoverflow.com/a/7320738/759019">answer</a>) makes sense from a mathematical perspective, it <strong>isn't as relevant</strong> when it comes to programming.</p> <blockquote> <p>The decision taken by the language specification &amp; compiler-designers is based on the decision made by computer system-designers to start count at 0.</p> </blockquote> <hr> <h3>The probable reason</h3> <p>Quoting from <strong>a Plea for Peace</strong> by Danny Cohen.</p> <ul> <li><a href="http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=1667115" rel="noreferrer">IEEE Link</a></li> <li><a href="http://www.ietf.org/rfc/ien/ien137.txt" rel="noreferrer">IEN-137</a></li> </ul> <blockquote> <p>For any base b, the first <strong>b^N</strong> non-negative integers are represented by exactly <strong>N</strong> digits (including leading zeros) only if numbering starts at 0.</p> </blockquote> <p>This can be tested quite easily. In base-2, take <code>2^3 = 8</code> The 8th number is:</p> <ul> <li>8 (binary: 1000) if we start count at 1</li> <li>7 (binary: 111) if we start count at 0</li> </ul> <p><code>111</code> can be represented using <code>3</code> bits, while <code>1000</code> will require an extra bit (4 bits).</p> <hr> <h3>Why is this relevant</h3> <p>Computer memory addresses have <code>2^N</code> cells addressed by <code>N</code> bits. Now if we start counting at 1, <code>2^N</code> cells would need <code>N+1</code> address lines. The extra-bit is needed to access exactly 1 address. (<code>1000</code> in the above case.). Another way to solve it would be to leave the last address inaccessible, and use <code>N</code> address lines. </p> <p>Both are <em>sub-optimal solutions</em>, compared to starting count at 0, which would keep all addresses accessible, using exactly <code>N</code> address lines!</p> <hr> <h3>Conclusion</h3> <p>The decision to start count at <code>0</code>, has since permeated <strong>all digital systems</strong>, including the software running on them, because it makes it simpler for the code to translate to what the underlying system can interpret. If it weren't so, there would be one unnecessary translation operation between the machine and programmer, for every array access. <strong>It makes compilation easier.</strong></p> <hr> <p><strong>Quoting from the paper:</strong></p> <p><img src="https://i.stack.imgur.com/RTs1Q.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload