<?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: Laiba</title>
    <description>The latest articles on DEV Community by Laiba (@laiba_90).</description>
    <link>https://dev.to/laiba_90</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%2F3899146%2F825616c4-1d6e-4200-9140-028e3710fbc8.png</url>
      <title>DEV Community: Laiba</title>
      <link>https://dev.to/laiba_90</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/laiba_90"/>
    <language>en</language>
    <item>
      <title>🕵️‍♂️ How Computers "Hide" a Minus Sign: The 2's Complement Trick</title>
      <dc:creator>Laiba</dc:creator>
      <pubDate>Sun, 26 Apr 2026 18:07:45 +0000</pubDate>
      <link>https://dev.to/laiba_90/how-computers-hide-a-minus-sign-the-2s-complement-trick-38f0</link>
      <guid>https://dev.to/laiba_90/how-computers-hide-a-minus-sign-the-2s-complement-trick-38f0</guid>
      <description>&lt;p&gt;Ever wondered how a computer stores a negative number? It doesn't have a tiny "minus" symbol inside the hardware. 🤖 &lt;/p&gt;

&lt;p&gt;Instead, it uses a clever mathematical ritual called &lt;strong&gt;Two’s Complement&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  The "Flip and Add" Recipe 🍳
&lt;/h3&gt;

&lt;p&gt;If you want to store &lt;strong&gt;-5&lt;/strong&gt; in an 8-bit &lt;code&gt;char&lt;/code&gt;, the computer doesn't just put a sign in front. It follows these three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Start with the Positive:&lt;/strong&gt; Write &lt;code&gt;5&lt;/code&gt; in binary $\rightarrow$ &lt;code&gt;00000101&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Flip the Bits:&lt;/strong&gt; Change every &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt; and every &lt;code&gt;1&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt; $\rightarrow$ &lt;code&gt;11111010&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Add 1:&lt;/strong&gt; Add a binary &lt;code&gt;1&lt;/code&gt; to that result $\rightarrow$ &lt;strong&gt;&lt;code&gt;11111011&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Boom!&lt;/strong&gt; That’s exactly how &lt;code&gt;-5&lt;/code&gt; sits in your memory.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why do we do this? (The Genius Part) 🧠
&lt;/h3&gt;

&lt;p&gt;Why not just change the first bit to &lt;code&gt;1&lt;/code&gt; and call it a day? &lt;/p&gt;

&lt;p&gt;Because with &lt;strong&gt;Two's Complement&lt;/strong&gt;, addition and subtraction work perfectly without any extra "brain power" from the CPU. When you add &lt;code&gt;5&lt;/code&gt; (&lt;code&gt;00000101&lt;/code&gt;) and &lt;code&gt;-5&lt;/code&gt; (&lt;code&gt;11111011&lt;/code&gt;), the bits naturally add up to &lt;strong&gt;0&lt;/strong&gt; (after a small overflow). &lt;/p&gt;

&lt;p&gt;It turns subtraction into simple addition! ➕&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚠️ The "Unsigned" Trap
&lt;/h3&gt;

&lt;p&gt;This is the part &lt;strong&gt;Love Babbar&lt;/strong&gt; often emphasizes: If you use an &lt;code&gt;unsigned&lt;/code&gt; variable, you are telling the computer: &lt;em&gt;"Ignore the minus sign glasses!"&lt;/em&gt; 👓&lt;/p&gt;

&lt;p&gt;If you store &lt;code&gt;-5&lt;/code&gt; in an &lt;code&gt;unsigned&lt;/code&gt; variable, the computer sees that leading &lt;code&gt;1&lt;/code&gt; and thinks it's a &lt;strong&gt;massive number&lt;/strong&gt; (like 4 billion) instead of a negative sign.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Lesson:&lt;/strong&gt; Bits are just bits. It’s the &lt;strong&gt;Data Type&lt;/strong&gt; that tells the computer how to read them!&lt;/p&gt;




&lt;h3&gt;
  
  
  🙌 Shoutout
&lt;/h3&gt;

&lt;p&gt;Huge thanks to &lt;strong&gt;Love Babbar&lt;/strong&gt; for the "Code Help"! 🚀 His explanation of how memory actually interprets these bits is a game-changer for understanding C++ foundations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What concept should I dive into next? DBMS or more C++ quirks? 👇&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>cpp</category>
      <category>softwareengineering</category>
      <category>womenintech</category>
    </item>
    <item>
      <title>🕵️‍♂️ The Case of the Vanishing Digits: Why 123,456 = 64?</title>
      <dc:creator>Laiba</dc:creator>
      <pubDate>Sun, 26 Apr 2026 17:39:38 +0000</pubDate>
      <link>https://dev.to/laiba_90/the-case-of-the-vanishing-digits-why-123456-64-5728</link>
      <guid>https://dev.to/laiba_90/the-case-of-the-vanishing-digits-why-123456-64-5728</guid>
      <description>&lt;p&gt;Ever had a piece of code do something so weird you thought your computer was possessed? 👻&lt;/p&gt;

&lt;p&gt;Check out this C++ mystery:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123456&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: 64 🤯&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a great idea! Acknowledging the mentors who helped you understand a concept adds a nice personal touch and builds community. Since you're currently working through his DBMS playlist and following his roadmap, it fits perfectly.&lt;/p&gt;

&lt;p&gt;Here is the updated version with a &lt;strong&gt;"Shoutout"&lt;/strong&gt; section included at the end:&lt;/p&gt;




&lt;h1&gt;
  
  
  🕵️‍♂️ The Case of the Vanishing Digits: Why 123,456 = 64?
&lt;/h1&gt;

&lt;p&gt;Ever had a piece of code do something so weird you thought your computer was possessed? 👻 &lt;/p&gt;

&lt;p&gt;Check out this C++ mystery:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123456&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: 64 🤯&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait... what? Where did the other &lt;strong&gt;123,392&lt;/strong&gt; go? Did the compiler steal them? 💸 &lt;/p&gt;

&lt;p&gt;Actually, it’s all about &lt;strong&gt;"The Teacup Rule."&lt;/strong&gt; ☕&lt;/p&gt;




&lt;h3&gt;
  
  
  1. The Container Problem 📦
&lt;/h3&gt;

&lt;p&gt;Think of a &lt;code&gt;char&lt;/code&gt; as a tiny &lt;strong&gt;teacup&lt;/strong&gt;. It can only hold &lt;strong&gt;8 bits&lt;/strong&gt; of data. &lt;/p&gt;

&lt;p&gt;The number &lt;strong&gt;123,456&lt;/strong&gt; is like a &lt;strong&gt;gallon of water&lt;/strong&gt;. When you try to pour a gallon into a teacup, you don't get a gallon-sized teacup... you just get a mess on the floor and a very full cup.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The "Binary Guillotine" ✂️
&lt;/h3&gt;

&lt;p&gt;Computers see numbers in binary (1s and 0s). Let’s look at what happened under the hood:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;123,456&lt;/strong&gt; in binary is: &lt;code&gt;1 11100010 01000000&lt;/code&gt; (17 bits long!)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A &lt;code&gt;char&lt;/code&gt;&lt;/strong&gt; only has room for the &lt;strong&gt;last 8 bits&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, C++ acts like a guillotine and chops off everything that doesn't fit:&lt;br&gt;
❌ &lt;strong&gt;Discarded:&lt;/strong&gt; &lt;code&gt;1 11100010&lt;/code&gt;&lt;br&gt;
✅ &lt;strong&gt;Kept:&lt;/strong&gt; &lt;code&gt;01000000&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The Math Magic ✨
&lt;/h3&gt;

&lt;p&gt;When we translate those leftover bits (&lt;code&gt;01000000&lt;/code&gt;) back into a decimal number, we get:&lt;br&gt;
&lt;strong&gt;$2^6 = 64$&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s why your output is 64! The computer didn't make a mistake; it just followed your instructions to squeeze a giant into a tiny box. 🧳&lt;/p&gt;




&lt;h3&gt;
  
  
  💡 The Takeaway
&lt;/h3&gt;

&lt;p&gt;This is called &lt;strong&gt;Data Truncation&lt;/strong&gt;. It’s a classic "gotcha" in programming. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro-Tip:&lt;/strong&gt; If you’re expecting big numbers, stay away from &lt;code&gt;char&lt;/code&gt;. Use &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;long long&lt;/code&gt; instead! Otherwise, your data might just "overflow" onto the floor. 🌊&lt;/p&gt;




&lt;h3&gt;
  
  
  🙌 A Special Shoutout
&lt;/h3&gt;

&lt;p&gt;I want to give a huge thanks to &lt;strong&gt;Love Babbar&lt;/strong&gt;! 🚀 His amazing teaching style and structured roadmaps have been a massive help in my journey of mastering these foundational concepts. If you're diving into DSA or DBMS, his content is a goldmine!&lt;/p&gt;




&lt;h3&gt;
  
  
  🛠️ Quick Challenge
&lt;/h3&gt;

&lt;p&gt;If you change the code to &lt;code&gt;cout &amp;lt;&amp;lt; ch;&lt;/code&gt; (without the &lt;code&gt;int&lt;/code&gt; part), you’ll see the &lt;strong&gt;@&lt;/strong&gt; symbol. Why? Because &lt;strong&gt;64&lt;/strong&gt; is the ASCII code for the &lt;strong&gt;@&lt;/strong&gt; sign! 📧&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Have you ever run into a bug where your numbers mysteriously changed? Let me know in the comments! 👇&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>softwareengineering</category>
      <category>lovebabbar</category>
    </item>
  </channel>
</rss>
