<?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[overFlowStackDeveloper - Medium]]></title>
        <description><![CDATA[Here you can find articles related for software development - Medium]]></description>
        <link>https://medium.com/overflowstackdeveloper?source=rss----11faffdfd86b---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>overFlowStackDeveloper - Medium</title>
            <link>https://medium.com/overflowstackdeveloper?source=rss----11faffdfd86b---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:36:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/overflowstackdeveloper" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React App To Convert Decimal Number To Binary]]></title>
            <link>https://medium.com/overflowstackdeveloper/react-app-to-convert-decimal-number-to-binary-d2dd26338152?source=rss----11faffdfd86b---4</link>
            <guid isPermaLink="false">https://medium.com/p/d2dd26338152</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Jack Martin]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 19:38:58 GMT</pubDate>
            <atom:updated>2024-08-18T19:38:58.446Z</atom:updated>
            <content:encoded><![CDATA[<p>Number which are represented with digits 0,1,2,3,4,5,6,7,8,9 are called decimal number. In case of binary we only use 0 and 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2VpIQP7Qdl1F8sqCAY-4w.png" /></figure><p>To convert a decimal number to binary you need perform repetitive division with 2 until you get the quotient as 0.</p><pre>import React, {useState} from &#39;react&#39;;<br>import &#39;./styles.css&#39;;</pre><p>We need to import the stylesheet file which contains the code for our CSS. useState() hook takes an initial state and return two values:</p><ul><li>current state</li><li>function that updates the state</li></ul><pre>export default function DecimalToBinary()</pre><p>Creating a functional component called DecimalToBinary.</p><pre>const [decimal, setDecimal] = useState(&#39;&#39;);<br>const [binary, setBinary] = useState(&#39;&#39;);</pre><p>You need to write down two useState hook. The first line declares a state variable decimal and setDecimal is the function to update it. The initial is an empty string. Similarly we have another state variable binary and setBinary is the function to update the binary state variable.</p><pre>const handleChange = (e) =&gt; {<br> setDecimal(e.target.value);<br>}</pre><p>handleChange is a function that takes an event ‘e’ as an argument. Whatever is the user enter the current state of decimal variable is updated using the setDecimal function.</p><pre>const convertToBinary = () =&gt; {<br> const decimalNumber = parseInt(decimal, 10);<br> if(isNaN(decimalNumber)) {<br>  setBinary(&#39;please enter a valid decimal number&#39;);<br>  return;<br> }<br> setBinary(decimalNumber.toString(2));<br>}</pre><p>You need to create a utility function. I’m calling it convertToBinary and it does not take any arguments.</p><p>‘const decimalNumber = parseInt(decimal, 10);’ we are taking whatever is stored in the state variable decimal in the useState hook and storing it in another variable decimalNumber with base 10.</p><p>using isNaN we are checking if the user has entered an invalid input instead of a number then set the binary state of the useState hook by setBinary function. Asking them to enter a valid number.</p><p>Otherwise using the inbuilt function toString(2) we are converting the value inside the variable decimalNumber to binary by passing 2 as an argument indicating the base. The result is set to the binary state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8fyKm013TbeISeE4HXJ0A.png" /></figure><pre>return(<br> &lt;div className=&quot;container&quot;&gt;<br>  &lt;h1&gt;Decimal to Binary converter&lt;/h1&gt;<br>  &lt;input <br>   type=&quot;text&quot;<br>   value={decimal}<br>   onChange={handleChange}<br>   placeholder=&quot;enter a decimal number&quot;<br>  /&gt;<br>  &lt;button onClick={convertToBinary}&gt;Convert&lt;/button&gt;<br>  {binary &amp;&amp; &lt;p&gt;binary: {binary}&lt;/p&gt;}<br> &lt;/div&gt;<br>)</pre><p>Complete github code: <a href="https://github.com/amanrock005/decimalToBinary/tree/main">https://github.com/amanrock005/decimalToBinary/tree/main</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2dd26338152" width="1" height="1" alt=""><hr><p><a href="https://medium.com/overflowstackdeveloper/react-app-to-convert-decimal-number-to-binary-d2dd26338152">React App To Convert Decimal Number To Binary</a> was originally published in <a href="https://medium.com/overflowstackdeveloper">overFlowStackDeveloper</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>