Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I don't understand how an int 63823, takes up less space than a double 1.0. Is there not more information stored in the int, in this particular instance?</p> </blockquote> <p>Good question. What you're seeing when you see <code>63823</code> and <code>1.0</code> is a <em>representation</em> of the underlying data, you are <em>not</em> seeing the underlying data. It is specially formatted so that <em>you</em> can read it, but it is <em>not</em> how the <em>machine</em> sees it.</p> <p>Java uses very special formats for representing <code>int</code> and <code>double</code>. You need to look at <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html" rel="nofollow noreferrer"><em>those</em> representations</a> to understand why <code>63823</code> takes thirty-two bits when represented as a Java <code>int</code> and <code>1.0</code> takes sixty-four bits when represented as a Java <code>double</code>.</p> <p>In particular, 63823 as an <code>int</code> in Java is <a href="https://stackoverflow.com/questions/13422259/how-are-integers-internally-represented-at-a-bit-level-in-java">represented </a>as:</p> <pre><code>00000000000000001111100101001111 </code></pre> <p>and 1.0 as a <code>double</code> is <a href="https://en.wikipedia.org/wiki/IEEE_floating_point" rel="nofollow noreferrer">represented</a> in Java as:</p> <pre><code>0011111111110000000000000000000000000000000000000000000000000000 </code></pre> <p>If you want to explore more, I recommend <a href="http://en.wikipedia.org/wiki/Two&#39;s_complement" rel="nofollow noreferrer">Two's Complement</a> and <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" rel="nofollow noreferrer">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a>.</p>
 

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