<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Twos-Complement on Zio Ivan</title>
    <link>https://ivandemarino.me/tags/twos-complement/</link>
    <description>Recent content in Twos-Complement on Zio Ivan</description>
    <generator>Hugo</generator>
    <language>en</language>
    <managingEditor>detronizator&#43;blog@gmail.com (Ivan De Marino, aka &#34;Zio Ivan&#34;, aka &#34;detro&#34;)</managingEditor>
    <webMaster>detronizator&#43;blog@gmail.com (Ivan De Marino, aka &#34;Zio Ivan&#34;, aka &#34;detro&#34;)</webMaster>
    <copyright>2004-2026 Ivan De Marino. Licensed under CC BY 4.0</copyright>
    <lastBuildDate>Wed, 13 Jan 2010 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://ivandemarino.me/tags/twos-complement/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Calculate abs(int) without branching</title>
      <link>https://ivandemarino.me/posts/calculate-abs-int-without-branching/</link>
      <pubDate>Wed, 13 Jan 2010 00:00:00 +0000</pubDate><author>detronizator&#43;blog@gmail.com (Ivan De Marino, aka &#34;Zio Ivan&#34;, aka &#34;detro&#34;)</author>
      <guid>https://ivandemarino.me/posts/calculate-abs-int-without-branching/</guid>
      <description>&lt;p&gt;For this you need someone to teach it to you: if you made it yourself, then you are a very good &lt;a href=&#34;http://en.wikipedia.org/wiki/Computer_science&#34;&gt;Comp-Sci&lt;/a&gt;, and you should send your CV to &lt;a href=&#34;http://www.google.co.uk/intl/en/jobs/&#34;&gt;Google&lt;/a&gt; ASAP. ;)&lt;/p&gt;
&lt;h2 id=&#34;without-branching-o_o&#34;&gt;Without branching O_o?&lt;/h2&gt;
&lt;p&gt;Yes, without using any &amp;ldquo;&lt;code&gt;if ( a &amp;lt; 0 )&amp;hellip;&lt;/code&gt;&amp;rdquo;. To do that, you need to refresh how &lt;a href=&#34;http://en.wikipedia.org/wiki/Two&#34;&gt;Two&amp;rsquo;s Complement works&lt;/a&gt;, then come back.&lt;/p&gt;
&lt;p&gt;What we really need to focus on is that, given a &lt;code&gt;signed int A&lt;/code&gt;, the negative of that number is: &lt;code&gt;B = ~A + 1&lt;/code&gt;. BUT, we are trying to calculate the Absolute Value, not the negative. So, something like:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
