title: Primitive DataType Casting in java - Internal Logic
body: <p>Guys i want to understand , how the widening or narrow implicit casting is internally implemented in java.I know that it involves bit fiddling.</p>
  
  <p>For example:</p>
  
  <pre><code>//implicit
  int i =2400;
  long a = (long)i; 
  
  //Explicit  
   float d = (float) 2.23423;
  </code></pre>
  
  <p><strong><em>Updates:</em></strong></p>
  
  <p>I wrote this post after looking at the question 
  posted here <a href="https://stackoverflow.com/questions/5351337/bitshifting-to-read-write-data">Bitshifting to read/write data</a>
  .Peter Lawrey gave the following answer.</p>
  
  <pre><code>public long create(int one, int two){
      return ((long) one &lt;&lt; 32) | (two &amp; 0xFFFFFFFFL);
  }
  </code></pre>
  
  <p>To re-iterate same,widening conversion like above happens at the machine level more or less with smiliar  same logic mentioned above by peter.</p>
  
  <p>kindly let me know your valuable comments.</p>