{"id":510,"date":"2013-07-18T11:22:01","date_gmt":"2013-07-18T18:22:01","guid":{"rendered":"http:\/\/192.168.1.2\/wordpress\/?p=510"},"modified":"2013-07-26T14:46:11","modified_gmt":"2013-07-26T21:46:11","slug":"common-bit-manipulation","status":"publish","type":"post","link":"http:\/\/cywang.no-ip.org\/wordpress\/?p=510","title":{"rendered":"Common Bit Manipulation"},"content":{"rendered":"<pre class=\"brush:cpp;\">\r\nbool getBit(int num, int shift)\r\n{\r\n&nbsp;return ( (num &amp; (1 &lt;&lt; shift)) != 0);\r\n}\r\nint setBit(int num, int shift)\r\n{\r\n&nbsp;return ( num | (1 &lt;&lt; shift));\r\n}\r\nint clearBit(int num, int shift)\r\n{\r\n&nbsp;int mask = ~ (1 &lt;&lt; shift);\r\n&nbsp;return num &amp; mask;\r\n}\r\nint clearBitMSBthroughShiftBit(int num, int shift)\r\n{\r\n&nbsp;int mask = (1 &lt;&lt; (shift )) -1;\r\n&nbsp;return num &amp; mask;\r\n}\r\nint clearBitMSBthroughShift0(int num, int shift)\r\n{\r\n&nbsp;int mask = ~ ((1 &lt;&lt; (shift +1 )) -1);\r\n&nbsp;return num &amp; mask;\r\n}\r\nint updateBit(int num, int shift, int v) \/\/set i-th bit = v\r\n{\r\n&nbsp;int mask = ~ (1 &lt;&lt; shift);\r\n&nbsp;return (num &amp; mask) | (v &lt;&lt; shift);\r\n}<\/pre>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>bool getBit(int num, int shift) { &nbsp;return ( (num &amp; (1 &lt;&lt; shift)) != 0); } int setBit(int num, int shift) { &nbsp;return ( num | (1 &lt;&lt; shift)); } int clearBit(int num, int shift) { &nbsp;int mask = ~ &hellip; <a href=\"http:\/\/cywang.no-ip.org\/wordpress\/?p=510\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[7,23],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-cc","category-chapter-5-bit-manipulation"],"_links":{"self":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=510"}],"version-history":[{"count":2,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":517,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions\/517"}],"wp:attachment":[{"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cywang.no-ip.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}