<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Govind Vijay</title>
    <description>The latest articles on DEV Community by Govind Vijay (@govvj).</description>
    <link>https://dev.to/govvj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F383946%2Fa7fa1d6a-5428-427e-a8e3-a9b4d3522dd6.png</url>
      <title>DEV Community: Govind Vijay</title>
      <link>https://dev.to/govvj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/govvj"/>
    <language>en</language>
    <item>
      <title>int to double type casting</title>
      <dc:creator>Govind Vijay</dc:creator>
      <pubDate>Wed, 15 Dec 2021 12:23:58 +0000</pubDate>
      <link>https://dev.to/govvj/int-to-double-type-casting-27id</link>
      <guid>https://dev.to/govvj/int-to-double-type-casting-27id</guid>
      <description>&lt;p&gt;Hi all,&lt;br&gt;
Say you have a 4 byte integer and now you want to convert it to double. You might say that's easy, just add couple of zeros to the front. It's not that simple. Its only work for positive integers.&lt;/p&gt;

&lt;p&gt;For simplicity lets assume you have 4 bit integer and you want to convert it to 8 bit.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Let a = -3 = (1101) -&amp;gt; 2's complement&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1101 -&amp;gt; 0010 (1s complement) + 1 -&amp;gt; 0011 -&amp;gt; 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you just add zeros then it will become &lt;br&gt;
&lt;code&gt;a = (00001101) = 13&lt;/code&gt;&lt;br&gt;
So instead you take the most significant digit (i.e. 4th bit) and paste it to the new bits.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_FBCKzK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cblnbtu1i5gyrempt6yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_FBCKzK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cblnbtu1i5gyrempt6yd.png" alt="copy msb bits" width="426" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;a = (11111101) = (00000010 + 1) = (00000011) = 3 -&amp;gt; -3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: when a = 13 we didn't do 2's complement because right most bit was zero.&lt;/p&gt;

</description>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
