Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The value of a <code>char</code> can be 0-255, where the different characters are mapped to one of these values. The numeric digits are also stored in order <code>'0'</code> through <code>'9'</code>, but they're also not typically stored as the first ten <code>char</code> values. That is, the character <code>'0'</code> doesn't have an ASCII value of <code>0</code>. The char value of <code>0</code> is almost always the <code>\0</code> null character.</p> <p>Without knowing anything else about ASCII, it's pretty straightforward how subtracting a <code>'0'</code> character from any other numeric character will result in the char value of the original character.</p> <p>So, it's simple math:</p> <pre><code>'0' - '0' = 0 // Char value of character 0 minus char value of character 0 // In ASCII, that is equivalent to this: 48 - 48 = 0 // '0' has a value of 48 on ASCII chart </code></pre> <p>So, similarly, I can do integer math with any of the <code>char</code> numberics...</p> <pre><code>(('3' - '0') + ('5' - '0') - ('2' - '0')) + '0') = '6' </code></pre> <p>The difference between <code>3</code>, <code>5</code>, or <code>2</code> and <code>0</code> on the ASCII chart is exactly equal to the face value we typically think of when we see that numeric digit. Subtracting the <code>char '0'</code> from each, adding them together, and then adding a <code>'0'</code> back at the end will give us the char value that represent the char that would be the result of doing that simple math.</p> <p>The code snippet above emulates <code>3 + 5 - 2</code>, but in ASCII, it's actually doing this:</p> <pre><code>((51 - 48) + (53 - 48) - (50 - 48)) + 48) = 54 </code></pre> <p>Because on the ASCII chart:</p> <pre><code>0 = 48 2 = 50 3 = 51 5 = 53 6 = 54 </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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