
{"id":337,"date":"2018-09-30T10:06:39","date_gmt":"2018-09-30T10:06:39","guid":{"rendered":"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/?page_id=337"},"modified":"2018-09-30T10:06:39","modified_gmt":"2018-09-30T10:06:39","slug":"logical-xor-glossary-entry","status":"publish","type":"page","link":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/glossary-2\/logical-xor-glossary-entry\/","title":{"rendered":"Logical XOR (Glossary Entry)"},"content":{"rendered":"<p>In digital electronics and software, we often meet the XOR function, also known as the <b>Exclusive OR<\/b>. This differs from the <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/logical-or-glossary-entry\/\" target=\"_blank\" rel=\"noopener\">inclusive OR<\/a>.\u00a0The logic symbols for an electronic XOR gate are as follows:<\/p>\n<figure id=\"attachment_338\" aria-describedby=\"caption-attachment-338\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-338\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR_Gate.png\" alt=\"\" width=\"300\" height=\"270\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR_Gate.png 650w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR_Gate-300x270.png 300w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-338\" class=\"wp-caption-text\">Schematic Symbols for the XOR Logic Gate<\/figcaption><\/figure>\n<p>The truth table for XOR is as follows:<\/p>\n<figure id=\"attachment_339\" aria-describedby=\"caption-attachment-339\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-339\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Truth-Table.png\" alt=\"\" width=\"400\" height=\"261\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Truth-Table.png 622w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Truth-Table-300x196.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><figcaption id=\"caption-attachment-339\" class=\"wp-caption-text\">Truth Table for the XOR Logic Gate<\/figcaption><\/figure>\n<p>In words, the output is 1 if <b>one and only one<\/b> input is set to 1. Some observations about this:<\/p>\n<ul>\n<li>If you XOR a bit \u2018A\u2019 with a 1, then the result is always a the opposite state (toggle)<\/li>\n<li>If you XOR a bit \u2018A\u2019 with a 0, then the result is A (preserved)<\/li>\n<\/ul>\n<p><i>We use these properties to <\/i><b><i>toggle or preserve<\/i><\/b><i> individual or groups of bits<\/i><\/p>\n<p>This is not limited to single bits. In software, we often perform logical operations on integers (binary numbers). Consider the following example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-340\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Example.png\" alt=\"\" width=\"1516\" height=\"490\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Example.png 1516w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Example-300x97.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Example-768x248.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/XOR-Example-1024x331.png 1024w\" sizes=\"auto, (max-width: 1516px) 100vw, 1516px\" \/><\/p>\n<p>The XOR function is applied to each pair of bits. In the C or C++ programming language, this could be calculated as:<\/p>\n<pre class=\"theme:xcode lang:c++ decode:true \">unsigned A = 162; \/\/A2 IN HEX\r\nA = A ^ 15;<\/pre>\n<p>The result is 173 <span class=\"Apple-converted-space\">\u00a0 <\/span>\/\/AD IN HEX<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In digital electronics and software, we often meet the XOR function, also known as the Exclusive OR. This differs from the inclusive OR.\u00a0The logic symbols for an electronic XOR gate are as follows: The truth table for XOR is as follows: In words, the output is 1 if one and only one input is set&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/glossary-2\/logical-xor-glossary-entry\/\">Continue reading <span class=\"screen-reader-text\">Logical XOR (Glossary Entry)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":153,"menu_order":44,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-337","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":1,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/337\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/337\/revisions\/341"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/153"}],"wp:attachment":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/media?parent=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}