<?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: Abhay Singh</title>
    <description>The latest articles on DEV Community by Abhay Singh (@abhay_singh_8374d82ce0825).</description>
    <link>https://dev.to/abhay_singh_8374d82ce0825</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%2F2361142%2F73138326-0c34-4bf4-8e6d-f8d1655a98b0.png</url>
      <title>DEV Community: Abhay Singh</title>
      <link>https://dev.to/abhay_singh_8374d82ce0825</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhay_singh_8374d82ce0825"/>
    <language>en</language>
    <item>
      <title>How to convert binary to decimal</title>
      <dc:creator>Abhay Singh</dc:creator>
      <pubDate>Tue, 10 Dec 2024 13:10:20 +0000</pubDate>
      <link>https://dev.to/abhay_singh_8374d82ce0825/how-to-convert-binary-to-decimal-5md</link>
      <guid>https://dev.to/abhay_singh_8374d82ce0825/how-to-convert-binary-to-decimal-5md</guid>
      <description>&lt;p&gt;&lt;a href="https://www.hexahome.in/area-converter-hmac/" rel="noopener noreferrer"&gt;Converting&lt;/a&gt; binary numbers to decimal is an essential skill in computer science and mathematics. This blog will explore two primary methods for performing this conversion: the Positional Notation Method and the Doubling Method.&lt;br&gt;
Understanding Binary and Decimal Systems&lt;br&gt;
Before diving into the conversion methods, it's crucial to understand the difference between binary and decimal systems:&lt;br&gt;
Binary System: A base-2 numeral system that uses only two digits, 0 and 1.&lt;br&gt;
Decimal System: A base-10 numeral system that uses ten digits, from 0 to 9.&lt;br&gt;
Conversion Methods&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Positional Notation Method
This method involves multiplying each binary digit by 
2
2 raised to the power of its position, starting from the rightmost digit (which is position 0).
Steps:
Write down the binary number.
Starting from the rightmost digit, assign powers of 
2
2 to each digit.
Multiply each binary digit by its corresponding power of 
2
2.
Sum all the results to get the decimal equivalent.
Example: Convert 
101
1
2
1011 
2
​
to decimal.
1
×
2
3
=
8
1×2 
3
=8
0
×
2
2
=
0
0×2 
2
=0
1
×
2
1
=
2
1×2 
1
=2
1
×
2
0
=
1
1×2 
0
=1
Adding these together gives:
8
+
0
+
2
+
1
=
11
8+0+2+1=11
Thus, 
101
1
2
=
1
1
10
1011 
2
​
=11 
10
​
.&lt;/li&gt;
&lt;li&gt;Doubling Method
This method involves starting from the leftmost digit and doubling the previous total while adding the current digit.
Steps:
Write down the binary number.
Start with a total of zero.
Move from left to right, doubling the total and adding the current binary digit at each step.
Example: Convert 
110
1
2
1101 
2
​
to decimal.
Start with an initial total of 
0
0.
For the first digit (1):
(
0
×
2
)
+
1
=
1
(0×2)+1=1
For the second digit (1):
(
1
×
2
)
+
1
=
3
(1×2)+1=3
For the third digit (0):
(
3
×
2
)
+
0
=
6
(3×2)+0=6
For the fourth digit (1):
(
6
×
2
)
+
1
=
13
(6×2)+1=13
Thus, 
110
1
2
=
1
3
10
1101 
2
​
=13 
10
​
.
Conclusion
Both methods are effective for converting binary numbers to decimal. The Positional Notation Method is more systematic and straightforward for those who prefer mathematical formulas, while the Doubling Method can be quicker for mental calculations or programming applications. With practice, anyone can master these &lt;a href="https://www.hexadecimalsoftware.com/" rel="noopener noreferrer"&gt;techniques&lt;/a&gt; and enhance their understanding of number systems in computing and mathematics.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>unitconversition</category>
      <category>binary</category>
      <category>decimal</category>
    </item>
    <item>
      <title>Converting Decimal to Hexadecimal in Python</title>
      <dc:creator>Abhay Singh</dc:creator>
      <pubDate>Wed, 06 Nov 2024 07:02:36 +0000</pubDate>
      <link>https://dev.to/abhay_singh_8374d82ce0825/converting-decimal-to-hexadecimal-in-python-8e6</link>
      <guid>https://dev.to/abhay_singh_8374d82ce0825/converting-decimal-to-hexadecimal-in-python-8e6</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decimal_to_hexadecimal(decimal_number):
    if decimal_number &amp;lt; 0:
        raise ValueError("Input must be a non-negative integer.")

    # Convert decimal to hexadecimal
    hexadecimal_number = hex(decimal_number)

    # Remove the '0x' prefix and return the result in uppercase
    return hexadecimal_number[2:].upper()

# Example usage
if __name__ == "__main__":
    try:
        decimal_input = int(input("Enter a non-negative decimal number: "))
        hex_output = decimal_to_hexadecimal(decimal_input)
        print(f"The hexadecimal representation of {decimal_input} is: {hex_output}")
    except ValueError as e:
        print(f"Error: {e}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of the Code&lt;br&gt;
Function Definition: The function decimal_to_&lt;a href="https://www.hexadecimalsoftware.com/" rel="noopener noreferrer"&gt;hexadecimal&lt;/a&gt; takes a single argument, decimal_number.&lt;br&gt;
Input Validation: It checks if the input is a non-negative integer. If not, it raises a ValueError.&lt;br&gt;
Conversion: The built-in hex() function converts the decimal number to hexadecimal. The result includes a '0x' prefix, which is removed by slicing the string.&lt;br&gt;
Output Formatting: The resulting hexadecimal string is converted to uppercase for consistency.&lt;br&gt;
Example Usage: The script prompts the user for input and displays the hexadecimal representation.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
