{"id":6701,"date":"2021-12-22T03:44:01","date_gmt":"2021-12-22T03:44:01","guid":{"rendered":"https:\/\/www.qec.tw\/?p=6701"},"modified":"2021-12-28T09:26:12","modified_gmt":"2021-12-28T09:26:12","slug":"compoundbitwiseand","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/86duino-reference\/compoundbitwiseand\/","title":{"rendered":"&#038;="},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[Compound Operators]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The compound bitwise AND operator (&amp;=) is often used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as \u201cclearing\u201d or \u201cresetting\u201d bits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>x &amp;= y; \/\/ equivalent to x = x &amp; y;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Parameters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>x<\/code>: a char, int or long variable<br><code>y<\/code>: an integer constant or char, int, or long<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, a review of the Bitwise AND (&amp;) operator<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>0  0  1  1    operand1\n0  1  0  1    operand2\n----------\n0  0  0  1    (operand1 &amp; operand2) - returned result<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Bits that are \u201cbitwise ANDed\u201d with 0 are cleared to 0 so, if myByte is a byte variable,<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>myByte &amp; B00000000 = 0;<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Bits that are \u201cbitwise ANDed\u201d with 1 are unchanged so,<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>myByte &amp; B11111111 = myByte;<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note: because we are dealing with bits in a bitwise operator \u2013 it is convenient to use the binary formatter with\u00a0<a href=\"http:\/\/www.86duino.com\/?p=1445\" target=\"_blank\" rel=\"noopener\">constants<\/a>. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero (hmmm something philosophical there?)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consequently \u2013 to clear (set to zero) bits 0 &amp; 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise AND operator (&amp;=) with the constant B11111100<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>         1 0 1 0 1 0 1 0    variable\n         1 1 1 1 1 1 0 0    mask\n         ----------------------\n         1 0 1 0 1 0 0 0\n  variable unchanged\n                     bits cleared<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the same representation with the variable\u2019s bits replaced with the symbol x.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>         x x x x x x x x    variable\n         1 1 1 1 1 1 0 0    mask\n         ----------------------\n         x x x x x x 0 0\n  variable unchanged\n                     bits cleared<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">So if:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>myByte = 10101010;\nmyByte &amp;= B1111100 == B10101000;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">See also<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>[Language]\u00a0|=\u00a0(compound bitwise or)<\/li><li>[Language]\u00a0<a href=\"https:\/\/www.qec.tw\/86duino-reference\/bitwiseand\/\">&amp;\u00a0<\/a>(bitwise AND)<\/li><li>[Language]\u00a0<a href=\"https:\/\/www.qec.tw\/86duino-reference\/bitwiseor\/\">|<\/a><a href=\"http:\/\/www.86duino.com\/?p=1411\" target=\"_blank\" rel=\"noopener\">\u00a0<\/a>(bitwise OR)<\/li><\/ul>\n\n\n<hr \/>\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.qec.tw\/86duino\/86duino-language-reference\/\">Language Reference Home<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The text of the 86Duino reference is a modification of&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Reference\/HomePage\" target=\"_blank\" rel=\"noopener\">the Arduino reference<\/a>&nbsp;and is licensed under a&nbsp;<a href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/\" target=\"_blank\" rel=\"noopener\">Creative Commons Attribution-ShareAlike 3.0 License<\/a>. Code samples in the reference are released into the public domain.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Compound Operators] Description The compound bitwise AND operator (&amp;=) is often used with a variable and a constant to force particular bits in a variable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6702,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[195],"tags":[162],"class_list":["post-6701","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-86duino-reference","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/6701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/comments?post=6701"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/6701\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/6702"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=6701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=6701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=6701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}