{"id":20,"date":"2007-08-21T18:16:02","date_gmt":"2007-08-21T22:16:02","guid":{"rendered":"http:\/\/www.ragestorm.net\/blogs\/?p=20"},"modified":"2007-08-21T18:16:02","modified_gmt":"2007-08-21T22:16:02","slug":"basic-ops-2-sub","status":"publish","type":"post","link":"https:\/\/www.ragestorm.net\/blogs\/?p=20","title":{"rendered":"Basic Ops #2 &#8211; Sub"},"content":{"rendered":"<p>As promised, but in a long delay, the algorithm for Subtraction. Just notice how similar it is to the Addtraction algorithm. Also, try to think why we use the bitwise not operator to make it a borrow rather than carry.<\/p>\n<p>unsigned int sub(unsigned int a, unsigned int b)<br \/>\n{<br \/>\n\u00a0\u00a0 a ^= b;<br \/>\n\u00a0\u00a0 b &amp;= ~(a ^ b);<br \/>\n\u00a0\u00a0 \u00a0while (b) {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0b &lt;&lt;= 1;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0a ^= b;<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0b &amp;= a;<br \/>\n\u00a0\u00a0 \u00a0}<br \/>\n\u00a0\u00a0 \u00a0return a;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised, but in a long delay, the algorithm for Subtraction. Just notice how similar it is to the Addtraction algorithm. Also, try to think why we use the bitwise not operator to make it a borrow rather than carry. unsigned int sub(unsigned int a, unsigned int b) { \u00a0\u00a0 a ^= b; \u00a0\u00a0 b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":""},"categories":[21],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbWKd-k","_links":{"self":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":0,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}