<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[semicolon.io - Medium]]></title>
        <description><![CDATA[Get knowledge about Computer Science here. - Medium]]></description>
        <link>https://medium.com/semicolon-io?source=rss----440774ffa0f0---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>semicolon.io - Medium</title>
            <link>https://medium.com/semicolon-io?source=rss----440774ffa0f0---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 27 May 2026 00:56:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/semicolon-io" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Why the negative sign is represented by 1 and not 0 in Binary.]]></title>
            <link>https://medium.com/semicolon-io/why-the-negative-sign-is-represented-by-1-and-not-0-in-binary-5f408006e6ab?source=rss----440774ffa0f0---4</link>
            <guid isPermaLink="false">https://medium.com/p/5f408006e6ab</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[binary-system]]></category>
            <dc:creator><![CDATA[Nipun Paradkar]]></dc:creator>
            <pubDate>Wed, 30 Aug 2017 07:12:02 GMT</pubDate>
            <atom:updated>2017-08-30T07:22:46.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOs0JJom4msyt5SmGV96nQ.jpeg" /></figure><p>I’m not sure about you, but I’ve certainly asked rather absurd looking questions like these to myself. Some of you might think it’s just a representational matter and it’s because it’s standardized. Surprisingly, there’s an actual reason why the negative sign is represented by a 1 in binary and not 0. If you can answer this question, kudos to you. If you can’t, then read on.</p><p>Being in Computer Science for almost half a decade, the Binary Number System has become second nature to me. That doesn’t mean that I can do Binary calculations in a second. I still need to write the numbers down and do the maths on paper. But one day while doing Binary calculations specifically with negative numbers, a weird thought came into my mind. “Why was the negative sign represented with a 1 rather than a 0?”. I knew the rules of Binary mathematics but just couldn’t figure it out until one day I stumbled upon the answer. It goes as follows.</p><p>Let’s take an example of a Binary number. Suppose the 8-bit number 11001010. Supposing that this number represents a signed decimal integer, it can be represented in <em>Positional Notation</em> as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*tSJPfaMmLkz7dCcaS0zS2Q.gif" /><figcaption>Formula 1: Traditional Positional Notation</figcaption></figure><p>Or in more simple terms…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*aiReosxjWC8vNpnwgn-5pg.gif" /><figcaption>Formula 2: Weighted Positional Notation</figcaption></figure><p>Now let’s find the value of the above formula in the Decimal System. Converting the number 11001010 to it’s twos complement gives us 00110110. Which means we can represent it like…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*gs4J6MhPcA_QJzS4SasB0w.gif" /><figcaption>Formula 3: Twos Complement Weighted Positional Notation</figcaption></figure><p>And then finding the value of the above formula gives us <em>54</em> as the answer. Which means the original number was <em>-54</em>.</p><p>This method of first converting a negative number to it’s positive twos compliment equivalent and then finding the value of that positive number in Decimal System and attaching a minus sign to it seems very tedious. But that’s what we’ve been taught since we encountered this Binary System. But it turns out that there’s an easier way of doing what we just did. And it all involves one slight change to the positional notation of the original negative number illustrated by <strong>Formula 2</strong>. And the change is…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*NFHzUrSrByeAlXLC_Hh4iQ.gif" /><figcaption>Formula 4: Signed Weighted Positional Notation of a Negative Number</figcaption></figure><p>If you didn’t notice, what I did is I made the weight of the <em>Most Significant Bit</em> of the original number into a negative number. It’s magnitude doesn’t change, only it’s sign. But watch how much of a significant change it does to our calculations. Finding the value of the above formula directly gives us <em>-54</em>.</p><p>You don’t need to do any kind of conversions to achieve the result. But the interesting thing is that it even works for positive numbers. For example let’s take the positive number 01001101. Representing the number in <strong>Signed Weighted Positional Notation</strong>, we get…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*GnMle_sPkxMExdqXnRtopA.gif" /><figcaption>Formula 5: Signed Weighted Positional Notation of a Positive Number</figcaption></figure><p>The value of the above formula is <em>77</em>, which would be equal to the value if you were to calculate it this way…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*YahuXktnW7naWdAvTdih5Q.gif" /><figcaption>Formula 6: Weighted Positional Notation of the same Positive Number</figcaption></figure><p>“But what does this have to do with your question?”, you ask. The answer is that, the <em>MSB</em> does not just represent a sign in a binary number but it actually represents a negative weight. And that’s why it makes sense, because if the <em>MSB</em> is 1, then the negative weight is included in the calculation to give you the correct negative value. And if the <em>MSB</em> is 0, then the negative weight is not included in the calculation to give you the correct positive number.</p><p>This is one of the times mathematics shows us how beautiful it can be.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f408006e6ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/semicolon-io/why-the-negative-sign-is-represented-by-1-and-not-0-in-binary-5f408006e6ab">Why the negative sign is represented by 1 and not 0 in Binary.</a> was originally published in <a href="https://medium.com/semicolon-io">semicolon.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attaching Event Handlers the smart way using Event Bubbling in JavaScript.]]></title>
            <link>https://medium.com/semicolon-io/attaching-event-handlers-the-smart-way-using-event-bubbling-in-javascript-7de1ef655727?source=rss----440774ffa0f0---4</link>
            <guid isPermaLink="false">https://medium.com/p/7de1ef655727</guid>
            <category><![CDATA[document-object-model]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nipun Paradkar]]></dc:creator>
            <pubDate>Tue, 29 Aug 2017 15:47:50 GMT</pubDate>
            <atom:updated>2017-08-30T04:50:21.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RG5QsjmFjeRzDQCg_gdDRw.jpeg" /></figure><p>I know how much <a href="https://jquery.com/"><em>jQuery</em></a> does tasks easier for a lot of people who are into Web Development. But personally for me, it makes my life complicated more than it makes it easy. Besides I always like to code in vanilla JavaScript because it makes me feel more accomplished.</p><p>One of the features of jQuery that vanilla JavaScript lacks unfortunately is the ability to attach <strong>Event Handlers</strong> to a collection of elements all at once. In JavaScript, to achieve the same functionality you have iterate over the collection attaching the same Event Handler to each item. But what a lot of people don’t know is the magic of <strong>Event Bubbling</strong> which can be used to achieve the same functionality; sort of!</p><p>Now Event Bubbling is not the same concept as attaching Event Handlers to a collection at once. Rather it’s an entirely different concept which can be used to achieve the same functionality. I took this example because it was easier to teach. It’s just one of the things you can do using Event Bubbling. Therefore what I’ll be teaching you is the concept of Event Bubbling with the specified example and then you’ll be free to decide what to do with the knowledge you’ve gained. Read on.</p><p>In simple terms, Event Bubbling is the act of firing the same event by all the ancestors of the target element which initially fired the event. So suppose we have the following code.</p><pre>&lt;div class=&quot;grand-parent&quot;&gt;<br>  &lt;div class=&quot;parent&quot;&gt;<br>    &lt;div class=&quot;child&quot;&gt;Click me!&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>Now if someone clicks the .child element, then not only the .child element will fire the click event but the .parent as well as the .grand-parent will fire the same click event successively. That is, first the .child element will fire click, then the .parent will do the same, and then the .grand-parent.</p><p>This concept is crucial as it will help us achieve the goal we’re looking out for. Let’s look at an example which will help you understand what’s going on under the hood. I’ve created an application which has a list of predefined superhero names. Users can add a superhero name to the list or delete a superhero name from the list. I’ve already coded the application and included the <em>pen</em>. Now let’s work through it. Explanation of the code is done through comments.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fradiantshaw%2Fpen%2FZJqdME&amp;src=https%3A%2F%2Fcodepen.io%2Fradiantshaw%2Fembed%2Fpreview%2FZJqdME%3Fheight%3D600%26slug-hash%3DZJqdME%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/16b12dec93d2a280f3afff279970d530/href">https://medium.com/media/16b12dec93d2a280f3afff279970d530/href</a></iframe><p>As you can see, attaching the Event Handler to the ancestors helps a lot to write short and concise code. One of the reasons I made the <strong>Add superhero name functionality</strong> is to show you the difference between using Event Bubbling and attaching the Event Handler directly to the target. Cause if you attach it directly to the target, then you have to go through a lot of overhead to find all the proper links to its ancestor elements and its siblings.</p><p>Ever since learning Event Bubbling I’m using it more often than I thought I would. Don’t be limited with what I just demonstrated. Try experimenting with these ideas and concepts and come up with new things. And if you do stumble upon them, do share!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7de1ef655727" width="1" height="1" alt=""><hr><p><a href="https://medium.com/semicolon-io/attaching-event-handlers-the-smart-way-using-event-bubbling-in-javascript-7de1ef655727">Attaching Event Handlers the smart way using Event Bubbling in JavaScript.</a> was originally published in <a href="https://medium.com/semicolon-io">semicolon.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>