{"id":17825,"date":"2020-08-30T10:15:18","date_gmt":"2020-08-30T10:15:18","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=17825"},"modified":"2022-07-24T10:11:39","modified_gmt":"2022-07-24T10:11:39","slug":"bitwise-operators-in-python","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/bitwise-operators-in-python\/","title":{"rendered":"Python Tutorials: Bitwise Operators In Python"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Bitwise operators are used to perform operations at binary digit level. These operators are not commonly used and are used only in special applications where optimized use of storage is required.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"205\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-opeartor-in-python.png\" alt=\"Table of Python bitwise operators &amp;, |, ^, ~, &lt;&lt; and &gt;&gt; with their meanings\" class=\"wp-image-17826\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-opeartor-in-python.png 525w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-opeartor-in-python-300x117.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise AND &amp;<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"242\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-and-operator-in-python.png\" alt=\"Bitwise AND truth table with a = 10 (00001010) and b = 15 (00001111) in binary\" class=\"wp-image-17827\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-and-operator-in-python.png 595w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-and-operator-in-python-300x122.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise OR |<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"239\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-or-operator-in-python.png\" alt=\"Bitwise OR truth table with a = 10 (00001010) and b = 15 (00001111) in binary\" class=\"wp-image-17828\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-or-operator-in-python.png 601w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-or-operator-in-python-300x119.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise XOR ^<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"603\" height=\"244\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-xor-operator-in-pyton.png\" alt=\"Bitwise XOR truth table with a = 10 (00001010) and b = 15 (00001111) in binary\" class=\"wp-image-17829\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-xor-operator-in-pyton.png 603w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-xor-operator-in-pyton-300x121.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise NOT ~<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"418\" height=\"182\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-not-in-python.png\" alt=\"Bitwise NOT truth table inverting 1 and 0, with a = 10 shown as 00001010\" class=\"wp-image-17830\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-not-in-python.png 418w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-not-in-python-300x131.png 300w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise Left Shift &lt;&lt;<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"219\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-left-shift-in-python.png\" alt=\"Diagram of a &lt;&lt; 2 shifting 00001010 left two places to give 00101000\" class=\"wp-image-17831\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-left-shift-in-python.png 705w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-left-shift-in-python-300x93.png 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Bitwise Right Shift &gt;&gt;<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"517\" height=\"237\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-right-sift.png\" alt=\"Diagram of a &gt;&gt; 2 shifting 00001010 right two places to give 00000010\" class=\"wp-image-17832\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-right-sift.png 517w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/08\/bitwise-right-sift-300x138.png 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_65880\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_13079\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_65880\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Bitwise operators are used to perform operations at binary digit level. These operators are not commonly used and are used only in special applications where optimized use&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[499],"tags":[],"class_list":["post-17825","post","type-post","status-publish","format-standard","hentry","category-python-programming-scripting-languages"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/17825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=17825"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/17825\/revisions"}],"predecessor-version":[{"id":30721,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/17825\/revisions\/30721"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=17825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=17825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=17825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}