<?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[Stories by Rich Song on Medium]]></title>
        <description><![CDATA[Stories by Rich Song on Medium]]></description>
        <link>https://medium.com/@ris0?source=rss-aec1a708074b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*umSQfn0xci2z9GK7w9xJkQ.jpeg</url>
            <title>Stories by Rich Song on Medium</title>
            <link>https://medium.com/@ris0?source=rss-aec1a708074b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:51:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ris0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Binary math and bitwise operators: Part 1]]></title>
            <link>https://medium.com/@ris0/binary-math-and-bitwise-operators-part-1-cbf4c938638d?source=rss-aec1a708074b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbf4c938638d</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rich Song]]></dc:creator>
            <pubDate>Mon, 24 Oct 2016 23:09:16 GMT</pubDate>
            <atom:updated>2016-10-24T23:10:44.147Z</atom:updated>
            <content:encoded><![CDATA[<p>For a variety of reasons, I haven’t spent a lot of time trying to learn binary math and bitwise operators. But as I continue down my path of becoming a master at programming, I am beginning to notice the importance of bitwise operators as they are often used for data compression, encryption, and bit flags. We typically use bitwise operators, especially on simple low-cost processors, because they are substantially faster than division, multiplication, and sometimes significantly faster than addition. In my recent experience, I find them to be extremely helpful when setting flags that correspond to a large assortment of configuration settings.</p><p>Before getting into binary math, let’s take a quick look at the decimals or the base-ten system. We have digits for the numbers zero through nine. We do not have a single-digit numeral for “ten”. Instead, when we need to count to one more than nine, we zero out the ones column and add one to the tens column. If we get too big in the tens column, we zero out the tens and ones columns, and add one to the ten-times-ten, or hundreds, column, and so forth. This might seem more natural because you and nearly every civilization has been doing base-ten math since the dawn of time. Binary math or base-two math is similar to what we just saw with the base-ten system. Each column’s value is represented by the powers of 2, which we use to tally up our numbers.</p><p><strong>Binary Math</strong></p><p>Binary or base-two math can be a little awkward and difficult at first, but with consistent practice, you can master this as well. Like with base-ten, when our number gets too big for that column, we carry over to the next column. This is where it is helpful to know the powers of 2.</p><p>2⁰ = 0</p><p>2¹ = 2</p><p>2² = 4</p><p>2³ = 8</p><p>2⁴ = 16</p><p>Each value here corresponds to a units column with base-two math. The first column in base-two math is the ones column. But only 0 or 1 can go in the units column. When you get to two, you find that there is no single solitary digit that stands for two in base-two math. Instead, you put a 1 in the twos column and a 0 in the ones column, indicating 1 two and 0 ones. Check out these examples below for a better understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*QZMSjc0wD14aAmOwChxQQw.png" /></figure><p>Are you starting to notice the pattern here? Each power of 2 corresponds to a column in base-two math. Of which, the numbers “0” or “1” in a column will denote the number value. For example, the decimal number 7, is comprised of: [ 4, 2, 1 ]. Notice that it is not [ 4, 3 ], because 3 does not exist in the powers of 2. So if we continue our example, we will mark “1” in each of those columns, so therefore our binary value is: 111.</p><p><strong>Some history</strong></p><p>Let’s take a step back and see how this all fits into the world of computer science. In computer architecture, 8-bit integers, memory addresses, or other data units are those that are at most 8 bits wide. This means that 8-bit CPUs that use an 8-bit data bus can only access 8 bits of data in a single machine instruction. These days we’re using 32-bit, 64-bit, or 86-bit CPUs and processing significantly more information at faster rates than ever before!</p><p><strong>Conversion tips</strong></p><p>Bitwise operators perform an action on the bits of a number, so if you want to understand how they work, it’s important that you know to convert decimals to binary and vice-versa.</p><p><strong>From decimal to binary</strong></p><p>If we have a decimal number, 783 for example, then we convert it to a binary number using this way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*HxFiQ-vAB1-9pgKLuAe3kw.png" /></figure><p>You have to stop dividing if the quotient is 0</p><p>Now, read the sequence from right to left, then you get the binary number: 1100001111</p><p><strong>From binary to decimal</strong></p><p>If you have a binary number: 0000000100010110 , then reverse the order of bits and use this method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*rvEjPYz1VzDLwlzioCiQaw.png" /></figure><p>Now, you have to add up all results:</p><p>0 + 2 + 4 + 16 + 0 + 0 + 0 + 256 + 0 + 0 + 0 + 0 + 0 + 0 + 0 = 278</p><p><strong>Next lesson</strong></p><p>In the next blog post, I’ll discuss the following bitwise operators:</p><ul><li>&amp; — Binary AND operator copies a bit to the result if it exists in both operands.</li><li>| — Binary OR operator copies a bit if it exists in either operand</li><li>^ — Binary XOR operator copies the bit if it is set in one operand but not both</li><li>~ — Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits</li><li>&lt;&lt; — Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand</li><li>&gt;&gt; — Binary Right Shift Operator — The left operands value is moved right by the number of bits specified by the right operand.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbf4c938638d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning with Analogies and Metaphors]]></title>
            <link>https://medium.com/@ris0/learning-with-analogies-and-metaphors-b2fc651e0c34?source=rss-aec1a708074b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2fc651e0c34</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Rich Song]]></dc:creator>
            <pubDate>Mon, 15 Aug 2016 15:12:09 GMT</pubDate>
            <atom:updated>2016-08-15T15:12:09.405Z</atom:updated>
            <content:encoded><![CDATA[<p>Science teachers and textbook writers differ widely in their enthusiasm for analogical explanation: some use many analogies while others are wary because they cannot predict how their students or readers will interpret the analogies they use to teach science.</p><p>I believe that analogies and metaphors are great for modeling or internalizing an abstract concept in a constructive way. By comparing a topic you understand poorly to something similar you understand better, you can come up with insights that result in a better understanding of the less-familiar topic.</p><p>A software metaphor is more like a searchlight than a road map. It doesn’t tell you where to find the answer; it tells you how to look for it. A metaphor serves more as a heuristic than it does as a deterministic algorithm. To further elaborate, a heuristic is a technique that helps you look for an answer. Its results are subject to chance because a heuristic tells you only how to look, not what to find.</p><p>With that said, you should take these metaphors and analogies with a grain of salt. Use them to give you insight into your programming problems and processes.</p><p><strong>Here are some of my favorite metaphors and analogies:</strong></p><p><strong>“</strong>Developing a program is like writing a casual letter- you sit down with pen, ink, and paper and write it from start to finish.”</p><p>“Envision creating software as something like planting seeds and growing crops.”</p><p>“It’s like the way an oyster makes a pearl, by gradually adding small amounts of calcium carbonate over time. It means that you have to learn how to add to your software systems a small amount at a time.”</p><p>“Treating software construction as similar to building construction suggests that careful preparation is needed and illuminates the difference between large and small projects.”</p><p>“Thinking of software-development practices as tools in an intellectual toolbox suggests further that every programmer has many tools and that no single tool is right for every job. Choosing the right tool for each problem is one key to being an effective programmer.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2fc651e0c34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction, Scope, and Functions]]></title>
            <link>https://medium.com/@ris0/random-javascript-lesson-1-e27ef7c62eb?source=rss-aec1a708074b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e27ef7c62eb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Rich Song]]></dc:creator>
            <pubDate>Thu, 11 Aug 2016 19:17:14 GMT</pubDate>
            <atom:updated>2016-08-15T14:30:10.382Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello world!</h3><p>In the past year, I have spent a lot of time and effort to become proficient in JavaScript. But I am slightly concerned that my skills will slowly diminish as I have recently started a new job that works with other languages. With that said, I am happy to announce that I will begin blogging to help me stay sharp.</p><p>Full disclosure: I am not a professional writer by any means, so please excuse my poor grammar. If you happen to stumble upon this blog, God bless your soul for trying to find useful information. This blog is not catered towards any particular type of developer. I plan on writing small posts on things that I am learning right now, things that I have learned in the past, and more!</p><p>Without further ado, I introduce to you a small but important lesson of JavaScript! This week’s post is a compilation of notes that I have taken from various sources, including You Don’t Know JS and 2ality!</p><p><strong>Scope</strong></p><p>In JavaScript, scope and closure are both incredibly important but be difficult to learn as a beginner. You can think of scope as a set of rules that determines where and how a variable can be looked-up. This look-up may be for the purposes of assigning to the variable, which is a left-hand-side reference, or it may be for the purposes of retrieving its value, which is an right-hand-side reference.</p><p>LHS references result from assignment operations. Scope-related assignments can occur either with the = operator or by passing arguments to function parameters.</p><p>The JavaScript Engine first compiles code before it executes, and in so doing, it splits up statements like var a = 2; into two separate steps;</p><ol><li>First, var a to declare it in that Scope.</li><li>Later, a = 2 to look up the variable and assign to it if found.</li></ol><p>Both LHS and RHS reference look-ups start at the currently executing Scope, and if need be, they work their way up the nested Scope, one scope at a time, looking for the identifier, until they get to the global and stop, and either find it, or don’t.</p><p>Scope look-up stops once it finds the first match. But the same identifier name can be specified at multiple layers of nested scope, which is called “shadowing”. Regardless of shadowing, scope look-up always starts at the innermost scope being executed at the time, and works its way outward/upward until the first match, and stops.</p><p>Keep in mind that global variables are also automatically properties of the global object (window in browsers), so it is possible to reference a global variable not directly by its lexical name, but instead indirectly as a property reference of the global objects.</p><p><strong>Scope from Functions</strong></p><p>In JavaScript, each function you declare creates a scope for itself. While functions are the most common unit of scope, and certainly the most wide-spread of the design approaches in the majority of JS in circulation, other units of scope are possible, and the usage of these other scope units can lead to even better, cleaner to maintain code.</p><p>Check this out:</p><pre>for (var i = 0; i&lt;10; i++) {<br>    console.log(‘hi’);<br>}</pre><p>We declare the variable i directly inside the for-loop head, most likely because our intent is to use i only within the context of that for-loop, and essentially ignore the fact that the variable actually scopes itself to the enclosing scope.</p><p>That’s what block-scoping is all about. Declaring variables as close as possible, as local as possible, to where they will be used.</p><p><strong>Function declaration vs. expression</strong></p><p>The easiest way to distinguish declaration vs. expression is the position of the word “function” in the statement. If “function” is the very first thing in the statement, then it’s a function declaration. Otherwise, it’s a function expression. The key difference we can observe here between a function declaration and a function expression relates to where its name is bound as an identifier.</p><p>In other words, (function foo(){ .. }) as an expression means the identifier foo is found only in the scope where the .. indicates, not in the outer scope. Hiding the name foo inside itself means it does not pollute the enclosing scope unnecessarily.</p><p>You are probably most familiar with function expressions as callback parameters, such as:</p><pre>setTimeout( function() {<br>    console.log(“I waited!”);<br>}, 1000 );</pre><p>This is called an “anonymous function expression”, because function()… has no name identifier on it. Function expressions can be anonymous, but function declarations cannot omit the name.</p><p><strong>To be continued…</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e27ef7c62eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>