{"id":1730,"date":"2017-05-18T13:23:49","date_gmt":"2017-05-18T13:23:49","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1730"},"modified":"2022-02-17T07:14:02","modified_gmt":"2022-02-17T07:14:02","slug":"bitwise-operators","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/boolean\/bitwise-operators","title":{"rendered":"Bitwise Operators"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">PHP Integers<\/h4>\n\n\n\n<p>Integer size is platform-dependent, safest is to assume a maximum value of about two billion (32 bits signed).<\/p>\n\n\n\n<p>64-bit platforms usually have a maximum value of about 9E18<\/p>\n\n\n\n<p>Unsigned integers are not supported in PHP<\/p>\n\n\n\n<p>If PHP encounters a number, or the result of an operation, that is beyond the bounds of the integer type, it will be interpreted as a float instead. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Operators you can use<\/h4>\n\n\n\n<p><a href=\"https:\/\/www.php.net\/manual\/en\/tokens.php\">https:\/\/www.php.net\/manual\/en\/tokens.php<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Bitwise AND<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\n  $StatusFlagGpsCommsOk = 0;\n  if ($StatusFlags &amp; 0x01)\n    $StatusFlagGpsCommsOk = 1;\n\n  $MyValue &amp;= 0x05;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Bit Shift<\/h4>\n\n\n\n<p>Doesn&#8217;t look like &gt;&gt;= and &lt;&lt;= can be used, but &lt;&lt; and &gt;&gt; are valid operators in PHP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyValue = 0x00001;\n  $MyValue = $MyValue &lt;&lt; 5;\n\n  $MyValue &lt;&lt;= 5;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Not<\/h4>\n\n\n\n<p>Bits that are set in $a are not set, and vice versa.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyVariable = ~(0);\n  $MyVariable = ~($MyVariable);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PHP Integers Integer size is platform-dependent, safest is to assume a maximum value of about two billion (32 bits signed). 64-bit platforms usually have a maximum value of about 9E18 Unsigned integers are not supported in PHP If PHP encounters a number, or the result of an operation, that is beyond the bounds of the [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,144,146],"tags":[],"class_list":["post-1730","post","type-post","status-publish","format-standard","hentry","category-bits","category-boolean","category-etc"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1730"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1730\/revisions"}],"predecessor-version":[{"id":3078,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1730\/revisions\/3078"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}