{"id":11521,"date":"2022-09-02T10:23:43","date_gmt":"2022-09-02T10:23:43","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=11521"},"modified":"2023-09-02T11:39:38","modified_gmt":"2023-09-02T06:09:38","slug":"bitwise-operators-in-c","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/","title":{"rendered":"Microcontroller Embedded C programming Lecture 97| Bitwise operators in &#8216;C&#8217;"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 35px; border-width: 0px; line-height: 45px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>Bitwise operators in &#8216;C&#8217;<\/strong><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<h2 class=\"\" style=\"font-size: 25px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #800080;\"><strong><span style=\"text-decoration: underline;\">Bitwise operators present in &#8216;C&#8217;:<\/span><\/strong><\/span><\/h2>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">There are six bitwise operators.<\/span><\/p>\n<figure id=\"attachment_11530\" aria-describedby=\"caption-attachment-11530\" style=\"width: 544px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-11530 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-1-1024x480.png\" alt=\"Figure 1. Bitwise operators in \u2018C\u2019\" width=\"544\" height=\"255\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-1024x480.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-300x141.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-768x360.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-600x281.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-1536x720.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-200x94.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-400x187.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-800x375.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1-1200x562.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png 1859w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><figcaption id=\"caption-attachment-11530\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Bitwise operators in \u2018C\u2019<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>1. Bitwise AND (<code>&amp;<\/code>)<\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><strong><span style=\"text-decoration: underline;\">Syntax:<\/span><\/strong><\/span> <code>result = operand1 &amp; operand2<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">It&nbsp; performs a bitwise AND operation between each corresponding pair of bits in the operands. The result is 1 only if both bits are 1; otherwise, the result is 0.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong><span style=\"text-decoration: underline;\">2. Bitwise OR (<code>|<\/code>):<\/span><\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><strong><span style=\"text-decoration: underline;\">Syntax:<\/span> <\/strong><\/span><code>result = operand1 | operand2<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">It performs a bitwise OR operation between each corresponding pair of bits in the operands. The result is 1 if either of the bits is 1; otherwise, the result is 0.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>3. Bitwise XOR (<code>^<\/code>)<\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><strong><span style=\"text-decoration: underline;\">Syntax:<\/span> <\/strong><\/span><code>result = operand1 ^ operand2<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">It performs a bitwise exclusive OR (XOR) operation between each corresponding pair of bits in the operands. The result is 1 if the bits are different; otherwise, the result is 0.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong><span style=\"text-decoration: underline;\">4. Bitwise NOT (<code>~<\/code>)<\/span><\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><strong><span style=\"text-decoration: underline;\">Syntax:<\/span><\/strong><\/span> <code>result = ~operand<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">It performs a bitwise NOT operation on each bit of the operand. It flips all the bits, turning 0 into 1 and 1 into 0.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 21px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Left shift (<code>&lt;&lt;<\/code>):<\/strong><\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"text-decoration: underline; color: #ff6600;\">Syntax: <\/span><\/strong><code>result = operand &lt;&lt; n<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">Shifts the bits of the operand to the left by n positions. Zeros are shifted in from the right, and the leftmost bits are discarded.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Right shift (<code>&gt;&gt;<\/code>):<\/strong><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><strong><span style=\"text-decoration: underline;\">Syntax:<\/span><\/strong><\/span> <code>result = operand &gt;&gt; n<\/code><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">Shifts the bits of the operand to the right by n positions. For unsigned values, zeros are shifted in from the left. For signed values, the behavior depends on the implementation-defined rules for signed right shift.<\/p>\n<p class=\"\">&nbsp;<\/p>\n<div class=\"mceTemp\"><\/div>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Bitwise operators are <span style=\"font-weight: 400;\">heavily used in Embedded system programming because most of the time in Embedded system programming, &#8216;C&#8217; is used.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Bitwise operators are used to manipulate memory addresses, contents of peripheral registers, status registers, etc. <\/span><span style=\"font-weight: 400;\">It is an important topic in Embedded &#8216;C&#8217; programming.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Bitwise operators allow us to perform operations on individual bits within a data type.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Understanding the bitwise operators and their usage can improve the efficiency of code, as it directly accesses the memory and register contents.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Bitwise operators have a wide range of applications in embedded systems such as setting\/clearing individual bits, masking operations, setting\/resetting flags, and more.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">It is crucial for an embedded system programmer to have a solid understanding of bitwise operators and their applications.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 23px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #003366;\"><strong>Difference between a Logical operator and a bitwise operator<\/strong><\/span><\/p>\n<blockquote class=\"\"><p><span style=\"font-weight: 400; color: #000000;\">If you use a double ampersand(<span style=\"color: #ff0000;\"><strong>&amp;&amp;<\/strong><\/span>), this is a <span style=\"color: #ff0000;\">&#8216;logical AND&#8217;<\/span> operator.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #000000;\">If you use a single ampersand(<span style=\"color: #ff0000;\"><strong>&amp;<\/strong><\/span>), this is the <span style=\"color: #ff0000;\">&#8216;bitwise AND&#8217;<\/span> operator.<\/span><\/p><\/blockquote>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #993366;\"><strong><span style=\"text-decoration: underline;\">Logical operator: <\/span><\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Logical operator is a type of operator that performs a logical operation on two values and returns a Boolean value of true or false. These operators are used in conditional statements and control flow in programming languages. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For example, the logical OR operator (||) returns true if either of its operands is true, and the logical AND operator (&amp;&amp;) returns true if both of its operands are true.<\/span><\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #993366;\"><strong><span style=\"text-decoration: underline;\">Bitwise operator:<\/span><\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">A bitwise operator, on the other hand, performs a bitwise operation on the binary representation of the values, manipulating individual bits. Bitwise operators are used to perform bit manipulation tasks such as masking, shifting, and setting bits. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For example, the bitwise OR operator (|) sets the bit to 1 if either of its operands has the corresponding bit set to 1, and the bitwise AND operator (&amp;) sets the bit to 0 if either of its operands has the corresponding bit set to 0.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In summary, logical operators are used to make logical comparisons between values, while bitwise operators are used to manipulate binary data.<\/span><\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<figure id=\"attachment_11531\" aria-describedby=\"caption-attachment-11531\" style=\"width: 556px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-11531 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-2-1024x451.png\" alt=\"Figure 2. Difference between logical operator and bitwise operator\" width=\"556\" height=\"245\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-1024x451.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-300x132.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-768x338.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-600x264.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-1536x677.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-200x88.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-400x176.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-800x352.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2-1200x529.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-2.png 1827w\" sizes=\"(max-width: 556px) 100vw, 556px\" \/><figcaption id=\"caption-attachment-11531\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Difference between logical operator and bitwise operator<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">To know how the operation is different.&nbsp; <\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s take an example, A = 40 and B =30. What is C = A&amp;&amp;B ?<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this case, A is 40; it is a non-zero value, so true. B is 30; also, it is a non-zero value, so it is true.&nbsp; The exact value of the A and B are not considered here. So, the only thing which matters is whether the operands are true(non-zero) or false(0).<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Since both of these operands are non-zero, the result will be true. So, C = 1 in this case.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff0000;\"><strong>How about C= A&amp;B operation? <\/strong><\/span><\/p>\n<figure id=\"attachment_11532\" aria-describedby=\"caption-attachment-11532\" style=\"width: 682px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-11532 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-3-1024x468.png\" alt=\"Figure 3. Bitwise AND operation calculation\" width=\"682\" height=\"312\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-1024x468.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-300x137.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-768x351.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-600x274.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-1536x701.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-200x91.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-400x183.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-800x365.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3-1200x548.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-3.png 1877w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><figcaption id=\"caption-attachment-11532\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Bitwise AND operation calculation<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this case, we do AND operation bit by bit. That&#8217;s why it is called a bitwise operation. Here, 00101000 is the binary format of the number 40, and 00011110 is the binary format of the number 30.<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, A &amp; B is nothing but you have to perform AND operation bit by bit. So, <strong>0&nbsp; &amp; 0<\/strong> is <strong>0<\/strong>; <strong>0 &amp; 1<\/strong> is <strong>0<\/strong>; <strong>1 &amp;1<\/strong> is <strong>1<\/strong>. So, C = 00001000, this is 8.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<blockquote class=\"\" style=\"background-color: #094070;\">\n<p class=\"\"><span style=\"color: #ffff00;\"><b>In bitwise operation, you do the operation like AND, OR, etc., bit by bit.<\/b><\/span><\/p>\n<\/blockquote>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s take an example with OR. <\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">A= 40 and B =30, what is the value of C= A|B?&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">A||B is a logical OR operation, so in this case, C =1.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the C = A|B case, you have to do the bitwise OR operation bit by bit. Here, <strong>0|0<\/strong> is <strong>0<\/strong>, <strong>0|1<\/strong> is <strong>1<\/strong>, <strong>1|1<\/strong> is <strong>1<\/strong>. So, C = 00111110, this turns out to be 62.&nbsp;<\/span><\/p>\n<figure id=\"attachment_11533\" aria-describedby=\"caption-attachment-11533\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11533 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-4-1-1024x507.png\" alt=\"Figure 4. Bitwise OR operation calculation\" width=\"711\" height=\"352\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-1024x507.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-300x148.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-768x380.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-600x297.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-1536x760.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-200x99.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-400x198.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-800x396.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1-1200x594.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-4-1.png 1889w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><figcaption id=\"caption-attachment-11533\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Bitwise OR operation calculation<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s explore the bitwise NOT operator.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"> <b>&#8216;~&#8217;<\/b><span style=\"font-weight: 400;\"> is a bitwise NOT operator, which is a unary operator because it needs only one operand. Bitwise NOT operator you write like <strong>~A<\/strong>. So, you cannot write <strong>A~<\/strong> (A negation).&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see what the value of C = ~A.<\/span><\/p>\n<figure id=\"attachment_11534\" aria-describedby=\"caption-attachment-11534\" style=\"width: 674px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11534\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-5-1-1024x482.png\" alt=\"Bitwise operators in C\" width=\"674\" height=\"317\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-1024x482.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-300x141.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-768x361.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-600x282.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-1536x722.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-200x94.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-400x188.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-800x376.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1-1200x564.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-5-1.png 1899w\" sizes=\"(max-width: 674px) 100vw, 674px\" \/><figcaption id=\"caption-attachment-11534\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Bitwise NOT operation calculation<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">A is 40. In binary, it is 00101000. The ~ A is you have to change 0&#8217;s into 1&#8217;s and 1&#8217;s into 0&#8217;s. That&#8217;s why ~A is 11010111, so C = -41 in this case. [minus because this is a signed variable].<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s about bitwise AND, bitwise OR, and bitwise NOT.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see bitwise XOR. There is no logical XOR and only a bitwise XOR operator.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">&nbsp;\u2018<\/span><b>^<\/b><span style=\"font-weight: 400;\">\u2019 is a bitwise XOR symbol, which does bit by bit XORing.&nbsp;<\/span><\/span><\/p>\n<figure id=\"attachment_11535\" aria-describedby=\"caption-attachment-11535\" style=\"width: 661px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11535\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/09\/Figure-6-1-1024x509.png\" alt=\"Bitwise operators in C\" width=\"661\" height=\"329\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-1024x509.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-768x382.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-600x298.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-1536x764.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-200x99.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-400x199.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-800x398.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1-1200x597.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-6-1.png 1889w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><figcaption id=\"caption-attachment-11535\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Bitwise XOR calculation<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The truth table of XOR is shown in Figure 6. <\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In the case of XORing, the output will be 1 only if the two operands are different. So, when both operands are different, the only output will be 1; if both operands are equal, then the output is 0. <\/span><span style=\"font-weight: 400;\">That&#8217;s how you should understand XOR.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 22px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #eb593f;\"><b>Applicability of bitwise operations<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In an Embedded C program, most of the time you will be doing,&nbsp;<\/span><\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #333399;\"><strong><a style=\"color: #333399; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-99-applicability-of-bitwise-operators-testing-of-bits\/\" target=\"_blank\" rel=\"noopener\">Testing of bits (&amp;)<\/a><\/strong><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #333399;\"><strong><a style=\"color: #333399; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-101-applicability-of-bitwise-operators-setting-of-bits\/\" target=\"_blank\" rel=\"noopener\">Setting of bits(|)<\/a><\/strong><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #333399;\"><strong><a style=\"color: #333399; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-102-applicability-of-bitwise-operators-clearing-of-bits\/\" target=\"_blank\" rel=\"noopener\">Clearing of bits(~ and &amp;)<\/a><\/strong><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #333399;\"><strong><a style=\"color: #333399;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-103-applicability-of-bitwise-operators-xor\/\" target=\"_blank\" rel=\"noopener\">Toggling of bits (^)<\/a><\/strong><\/span><\/li>\n<\/ul>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, because your LED is connected to one of the pins of the microcontroller port, if you want to turn on the LED, you are going to set some bit. If you want to turn off the LED, you will clear some bits, and if you want to analyze the status register of a peripheral, you&#8217;ll be using testing of bits. So, we&#8217;ll use the bitwise operators in all those cases.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s do the below exercise in<span style=\"color: #0000ff;\"> <a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/bitwise-and-and-bitwise-or\/\" target=\"_blank\" rel=\"noopener\">following article<\/a><\/span>.<\/span><\/p>\n<p class=\"\" style=\"font-size: 18px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Exercise<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Write a program which takes 2 integers from the user, computes bitwise &amp;, bitwise |, bitwise ^, and ~ and prints the result.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 1.8em; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 18px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Bitwise operators in &#8216;C&#8217; &nbsp; &nbsp; Bitwise operators present in &#8216;C&#8217;: There are six bitwise operators. &nbsp; 1. Bitwise AND (&amp;) Syntax: result = operand1 &amp; operand2 It&nbsp; performs a bitwise AND operation between each corresponding pair of bits in the operands. The result is 1 only if both bits are 1; otherwise, the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11530,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"enable","ocean_disable_heading":"default","ocean_post_title":"Bitwise operators in C programming","ocean_post_subheading":"","ocean_post_title_style":"solid-color","ocean_post_title_background_color":"#208adb","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-11521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bitwise operators in C Programming - Example, Applicability<\/title>\n<meta name=\"description\" content=\"Bitwise operators in C programming. There are six bitwise operators - &amp; (AND), | (OR), ^ (XOR),~ (NOT),&lt;&lt; (Left shift), &gt;&gt; (Right shift). In Embedded systems\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bitwise operators in C Programming - Example, Applicability\" \/>\n<meta property=\"og:description\" content=\"Bitwise operators in C programming. There are six bitwise operators - &amp; (AND), | (OR), ^ (XOR),~ (NOT),&lt;&lt; (Left shift), &gt;&gt; (Right shift). In Embedded systems\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-02T10:23:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-02T06:09:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1859\" \/>\n\t<meta property=\"og:image:height\" content=\"871\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C programming Lecture 97| Bitwise operators in &#8216;C&#8217;\",\"datePublished\":\"2022-09-02T10:23:43+00:00\",\"dateModified\":\"2023-09-02T06:09:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/\"},\"wordCount\":1214,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/Figure-1.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/\",\"name\":\"Bitwise operators in C Programming - Example, Applicability\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/Figure-1.png\",\"datePublished\":\"2022-09-02T10:23:43+00:00\",\"dateModified\":\"2023-09-02T06:09:38+00:00\",\"description\":\"Bitwise operators in C programming. There are six bitwise operators - & (AND), | (OR), ^ (XOR),~ (NOT),&lt;< (Left shift), >> (Right shift). In Embedded systems\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/Figure-1.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/Figure-1.png\",\"width\":1859,\"height\":871,\"caption\":\"Figure 1. Bitwise operators in \u2018C\u2019\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/bitwise-operators-in-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C programming Lecture 97| Bitwise operators in &#8216;C&#8217;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bitwise operators in C Programming - Example, Applicability","description":"Bitwise operators in C programming. There are six bitwise operators - & (AND), | (OR), ^ (XOR),~ (NOT),&lt;< (Left shift), >> (Right shift). In Embedded systems","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Bitwise operators in C Programming - Example, Applicability","og_description":"Bitwise operators in C programming. There are six bitwise operators - & (AND), | (OR), ^ (XOR),~ (NOT),&lt;< (Left shift), >> (Right shift). In Embedded systems","og_url":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-09-02T10:23:43+00:00","article_modified_time":"2023-09-02T06:09:38+00:00","og_image":[{"width":1859,"height":871,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C programming Lecture 97| Bitwise operators in &#8216;C&#8217;","datePublished":"2022-09-02T10:23:43+00:00","dateModified":"2023-09-02T06:09:38+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/"},"wordCount":1214,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/","url":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/","name":"Bitwise operators in C Programming - Example, Applicability","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png","datePublished":"2022-09-02T10:23:43+00:00","dateModified":"2023-09-02T06:09:38+00:00","description":"Bitwise operators in C programming. There are six bitwise operators - & (AND), | (OR), ^ (XOR),~ (NOT),&lt;< (Left shift), >> (Right shift). In Embedded systems","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/09\/Figure-1.png","width":1859,"height":871,"caption":"Figure 1. Bitwise operators in \u2018C\u2019"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/bitwise-operators-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C programming Lecture 97| Bitwise operators in &#8216;C&#8217;"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=11521"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11521\/revisions"}],"predecessor-version":[{"id":15609,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/11521\/revisions\/15609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/11530"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=11521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=11521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=11521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}