<?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 Ankit Thakur on Medium]]></title>
        <description><![CDATA[Stories by Ankit Thakur on Medium]]></description>
        <link>https://medium.com/@at4308?source=rss-1f3f8c2bb151------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8bXScUsqG0sqdAoi.jpg</url>
            <title>Stories by Ankit Thakur on Medium</title>
            <link>https://medium.com/@at4308?source=rss-1f3f8c2bb151------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:36:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@at4308/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[How to calculate the Hamming distance]]></title>
            <link>https://medium.com/@at4308/how-to-calculate-the-hamming-distance-20bd062963f7?source=rss-1f3f8c2bb151------2</link>
            <guid isPermaLink="false">https://medium.com/p/20bd062963f7</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ankit Thakur]]></dc:creator>
            <pubDate>Wed, 08 Jul 2020 23:35:00 GMT</pubDate>
            <atom:updated>2020-07-10T04:48:43.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndlG5ErgJIY6Q1kTBeC0XQ.jpeg" /></figure><p>so this can be solved using bitwise operators</p><p>firstly we will do xor of 2 numbers</p><p>then calculate the bitset</p><p><strong>XOR</strong></p><p>if both the bits are same then we get 0</p><p>otherwise 1</p><p>so total number of 1’s after xor of 2 numbers=hamming distacnce between 2 numbers</p><p>like if we take xor of 5 and 8</p><p>5 in binary is 0101</p><p>And 8 in binary is 1000</p><p>we get 1101 and as you see there 3 one’s</p><p>so the hamming distance between 5 and 8 is 3</p><p><strong>Bitset(number of 1 bits)</strong></p><p>we can calculate this using n=n&amp;(n-1)</p><p>till n will not become zero .</p><p>total iteration will be number of 1.</p><p>Here is the code</p><p>int hammingDistance(int x, int y)</p><p>{</p><p>int nums=x^y;</p><p>if(nums&gt;0)</p><p>{</p><p>nums=nums&amp;(nums-1);</p><p>int count=1;</p><p>while(nums)</p><p>{</p><p>nums=nums&amp;(nums-1);</p><p>count++;</p><p>}</p><p>return count;</p><p>}</p><p>else</p><p>return 0;</p><p>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20bd062963f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>