{"id":3825,"date":"2020-08-05T01:08:26","date_gmt":"2020-08-04T19:38:26","guid":{"rendered":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/?p=3825"},"modified":"2021-06-14T15:37:26","modified_gmt":"2021-06-14T10:07:26","slug":"python-bitstring","status":"publish","type":"post","link":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/","title":{"rendered":"Python Bitstring: Classes and 6 Examples | Module"},"content":{"rendered":"\n<p>Want to understand and work on the language which your computer and <strong>languages like python understand<\/strong>? Just go through this article one, we will help you achieve your goal. In this article, we will learn about an exciting module in python known as<strong> python bitstring<\/strong>.<\/p>\n\n\n\n<p><strong>Python Bitstring is generally defined as a module that makes the creation, analysis, and manipulation of binary data (<em>contains only 0 and 1)<\/em> simple and natural.\u00a0<\/strong><\/p>\n\n\n\n<p>We will see how we can create bitstrings and how to perform operations on them. And if you are working on Python 2.7, you don\u2019t need to worry, and the python bitstring module supports both versions- <em>2.7 and 3.<\/em>&nbsp;<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Syntax_of_Python_Bitstring_Module\" title=\"Syntax of Python Bitstring Module\">Syntax of Python Bitstring Module<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Classes_in_Bitstring_module\" title=\"Classes in Bitstring module&nbsp;\">Classes in Bitstring module&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Return_Type_Python_Bitstring\" title=\"Return Type Python Bitstring-&nbsp;&nbsp;\">Return Type Python Bitstring-&nbsp;&nbsp;<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Implementing_the_Python_Bitstring_module\" title=\"Implementing the Python Bitstring module\">Implementing the Python Bitstring module<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#a_Converting_Various_datatypes_into_BitString\" title=\"a. Converting Various datatypes into BitString\">a. Converting Various datatypes into BitString<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#b_How_to_append_into_python_bitstring\" title=\"b. How to append into python bitstring \">b. How to append into python bitstring <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#c_Performing_Slicing_Operation\" title=\"c. Performing Slicing Operation\">c. Performing Slicing Operation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#d_Creating_a_ConstBitStream_and_performing_peek_operation_on_it\" title=\"d. Creating a ConstBitStream and performing peek operation on it\">d. Creating a ConstBitStream and performing peek operation on it<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#e_Reading_the_bitstring\" title=\"e.  Reading the bitstring\">e.  Reading the bitstring<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#f_Working_on_BitStream_Class\" title=\"f. Working on BitStream Class\">f. Working on BitStream Class<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Must_Read\" title=\"Must Read:\">Must Read:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#Conclusion\" title=\"Conclusion \">Conclusion <\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-syntax-of-python-bitstring-module\"><span class=\"ez-toc-section\" id=\"Syntax_of_Python_Bitstring_Module\"><\/span>Syntax of Python Bitstring Module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We cannot use the module until and unless we install it in our systems.&nbsp;&nbsp;<\/p>\n\n\n\n<p><em><strong>To install use \u2013 pip install bitstring.<\/strong>&nbsp;<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-classes-in-bitstring-module\"><span class=\"ez-toc-section\" id=\"Classes_in_Bitstring_module\"><\/span>Classes in Bitstring module&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The main aim of the module is to help us in working with<strong> Binary data<\/strong> in python programming language and make it as easy as possible. And that is why the module compromises <strong>four classes<\/strong>, which will help us accomplish all of our tasks. Let us understand the basics of each one of them.&nbsp;&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-bits-auto-none-length-none-offset-none-kwargs\">Bits(auto=None, length=None, offset=None, **kwargs)&nbsp;<\/h4>\n\n\n\n<p>The primary use of this class is to create a container that holds an<em> immutable<\/em> <em>sequence of bits<\/em>. By immutable, we mean that it cannot be changed after creation.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong><em>Parameters<\/em><\/strong>&#8211;&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Auto:<\/strong> It can be a string of comma-separated <strong>tokens, an integer, a file object, a bytearray, a boolean iterable, an array, or another bitstring.<\/strong> By default, it is None, and you can leave it like that by using a keyword argument.&nbsp;<\/p>\n\n\n\n<p><strong>length<\/strong>: the length of the bitstring in bits, if needed and appropriate. It must be supplied for all integer and float initializers. The valid values for length for float is either 32 or 64.&nbsp;<\/p>\n\n\n\n<p><strong>Offset:<\/strong> This parameter can only be used when we are using bytes or filename initializers. If we want to ignore some of the starting bits, we can use the offset parameter.&nbsp;<\/p>\n\n\n\n<p><strong>**kwargs:<\/strong> In this parameter, we can give the type and value from which we want to create a bitstring. It can be bytes, bin, hex, oct, uint (unsigned int), int, filename, and many more types.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Return Type Python bitstring . bits:&nbsp;<\/strong><\/p>\n\n\n\n<p><em>It returns &#8216;bitstring.Bits&#8217; type of output.&nbsp;<\/em><\/p>\n\n\n\n<p>Some of the common methods are <strong><em>all(), any(), count(), endswith(), find()<\/em><\/strong>. We are not going to study the theoretical part of these methods because doing that now will make the topic rather confusing. We will try to use them in our programs later on.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-class-bitstring-bitarray-auto-length-offset-kwargs-of-python-bitstring\">class bitstring.BitArray([auto, length, offset, **kwargs])&nbsp;of python Bitstring<\/h4>\n\n\n\n<p>This class is the derived class of Bits class, which we studied earlier. The primary and fundamental difference is that <a href=\"https:\/\/www.pythonpool.com\/python-bitarray\/\" target=\"_blank\" rel=\"noreferrer noopener\">BitArray<\/a> returns<em> mutable bitstrings<\/em>. It means the content of bits can be modified after once created.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Parameters are the same for BitArray class are the same so that you can refer them from above.&nbsp;<\/p>\n\n\n\n<p><strong>Return Type:&nbsp;<\/strong><\/p>\n\n\n\n<p><em>&lt;class &#8216;bitstring.BitArray&#8217;&gt;&nbsp;<\/em><\/p>\n\n\n\n<p>Some common methods are <strong>append(bs), byteswap(), clear(), insert().&nbsp;<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-bitstring-constbitstream-auto-length-offset-kwargs\">bitstring.ConstBitStream([auto, length, offset, **kwargs])&nbsp;<\/h4>\n\n\n\n<p>This class is also a derived class of Bits class. All the methods available in Bits class are available in the<em> ConstBitStream class<\/em>. The auto initializer is also the same. In ConstBitStream, the class has some <em>added properties and methods which allow bits to be parsed as a stream.&nbsp;<\/em><\/p>\n\n\n\n<p>We are not going to discuss parameters because they are the same as above.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-return-type-python-bitstring\"><span class=\"ez-toc-section\" id=\"Return_Type_Python_Bitstring\"><\/span><strong>Return Type Python Bitstring-&nbsp;&nbsp;<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><em>&lt;class &#8216;bitstring.ConstBitStream&#8217;&gt;&nbsp;<\/em><\/p>\n\n\n\n<p>Some common methods are bytealign(), peek(), peeklist().&nbsp;&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-bitstring-bitstream\">Bitstring.BitStream()&nbsp;<\/h4>\n\n\n\n<p>This class is almost the same as the ConstBitStream class. The only difference is that this class allows mutable bit steams.&nbsp;<\/p>\n\n\n\n<p>Return Type-&nbsp;<\/p>\n\n\n\n<p>&lt;class &#8216;bitstring.BitStream\u2019>\u00a0<\/p>\n\n\n\n<p>Enough of theory for now! Let us directly jump to the <a href=\"https:\/\/www.dictionary.com\/browse\/practical\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\">practical<\/a> part of this module.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-implementing-the-python-bitstring-module\"><span class=\"ez-toc-section\" id=\"Implementing_the_Python_Bitstring_module\"><\/span>Implementing the Python Bitstring module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Following examples demonstrate the usage of Bitstring module &#8211;<\/p>\n\n\n\n<ol><li><strong>Converting Various datatypes into BitString<\/strong><\/li><li><strong>How to append into python bitstring<\/strong><\/li><li><strong>Performing Slicing Operation<\/strong><\/li><li><strong>Creating a ConstBitStream and performing peek operation on it<\/strong><\/li><li><strong>Reading the bitstring<\/strong><\/li><li><strong>Working on BitStream Class<\/strong><\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-converting-various-datatypes-into-bitstring\"><span class=\"ez-toc-section\" id=\"a_Converting_Various_datatypes_into_BitString\"><\/span>a. Converting Various datatypes into BitString<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom bitstring import Bits\n#Converting a hexadecimal into bitstring\nstring1 = Bits(hex='0xff470001')\n#Converting a octadecimal into bitstring\nstring2 = Bits(oct='0o4464')\n#Converting a binary string into bitstring\nstring3 = Bits(bin='0b001010110101')\n#Converting a integerl into bitstring\nstring4 = Bits(int=-1540, length=12)\n#Converting a unsigned integer into bitstring\nstring5 = Bits(uint=2300, length=12)\n#Converting a bytes into bitstring\nstring6 = Bits(bytes=b'\\x93@', length=12)\nprint(string1)\nprint(string2)\nprint(string3)\nprint(string4)\nprint(string5)\nprint(string6)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"685\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1-1024x685.png\" alt=\"python bitstring\" class=\"wp-image-3826\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1-1024x685.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1-300x201.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1-768x514.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1-1536x1028.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-1.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">0xff470001\n0x934\n0x2b5\n0x9fc\n0x8fc\n0x934<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-b-how-to-append-into-python-bitstring\"><span class=\"ez-toc-section\" id=\"b_How_to_append_into_python_bitstring\"><\/span>b. How to append into python bitstring <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We cannot append on Bits class, but we can use BitArray class for the same.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom bitstring import BitArray\nbas = BitArray('0xbad')\n# appending hexadecimal string at last\nbas.append(&quot;0xff470001&quot;)\nprint(bas)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">0xbadff470001<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-c-performing-slicing-operation\"><span class=\"ez-toc-section\" id=\"c_Performing_Slicing_Operation\"><\/span>c. Performing Slicing Operation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nba = BitArray('0b00011110')\n# We can perform slicing on the bitstring\nb = ba&#x5B;3:7]\nprint(&quot;Original string:&quot;,ba)\nprint(&quot;Sliced string:&quot;,b)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">Original string: 0x1e \nSliced string: 0xf<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-d-creating-a-constbitstream-and-performing-peek-operation-on-it\"><span class=\"ez-toc-section\" id=\"d_Creating_a_ConstBitStream_and_performing_peek_operation_on_it\"><\/span>d. Creating a ConstBitStream and performing peek operation on it<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom bitstring import ConstBitStream\ns = ConstBitStream('0xff47000')\ns.peek('hex:12') # integer is 4 bytes\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">'ff4'<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-e-reading-the-bitstring\"><span class=\"ez-toc-section\" id=\"e_Reading_the_bitstring\"><\/span>e.  Reading the bitstring<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ns = ConstBitStream('0x12345678')\nprint(s.read(12))\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">0x123<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-f-working-on-bitstream-class\"><span class=\"ez-toc-section\" id=\"f_Working_on_BitStream_Class\"><\/span>f. Working on BitStream Class<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom bitstring import BitStream\nstring = BitStream(oct='0o4464')\nstring.append('0o4')\nprint(string)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">0b100100110100100<\/pre>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul><li><a href=\"https:\/\/www.pythonpool.com\/python-lowercase\/\">How to Convert String to Lowercase in<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/square-root-in-python\/\">How to Calculate Square Root<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/python-user-input\/\">User Input | Input () Function | Keyboard Input<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/python-book\/\">Best Book to Learn Python<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Python Bitstring<\/strong> module has made it very easy for us to play with bits and bytes (0&#8217;s and 1&#8217;s). There are 4 classes and many methods in the module. Please explore and try learning even more methods.<\/p>\n\n\n\n<p>Try to run the programs on your side and let us know if you have any queries.<\/p>\n\n\n\n<p><strong><em>Happy Coding!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to understand and work on the language which your computer and languages like python understand? Just go through this article one, we will help &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Python Bitstring: Classes and 6 Examples | Module\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/#more-3825\" aria-label=\"More on Python Bitstring: Classes and 6 Examples | Module\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":3833,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[296,15],"tags":[1945,1940,1935,1942,1936,1941,1946,1939,1938,1947,1943,1944,1937],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v22.4) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Bitstring: Classes and 6 Examples | Module - Python Pool<\/title>\n<meta name=\"description\" content=\"Python Bitstring module has made it really easy or us to work with bits. We can convert strings, integer, bytes, hexadecimal into bitstrings.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-bitstring\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Bitstring: Classes and 6 Examples | Module\" \/>\n<meta property=\"og:description\" content=\"Want to understand and work on the language which your computer and languages like python understand? Just go through this article one, we will help you\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-bitstring\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-04T19:38:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-14T10:07:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"264\" \/>\n\t<meta property=\"og:image:height\" content=\"159\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashwini Mandani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashwini Mandani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/\"},\"author\":{\"name\":\"Ashwini Mandani\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\"},\"headline\":\"Python Bitstring: Classes and 6 Examples | Module\",\"datePublished\":\"2020-08-04T19:38:26+00:00\",\"dateModified\":\"2021-06-14T10:07:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/\"},\"wordCount\":854,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png\",\"keywords\":[\"bitstring module python\",\"bitstring python\",\"bitstring to bits python\",\"convert hex string to bitstring python\",\"print bitstring python formatte\",\"python bitarray bitstring\",\"python bitstring\",\"python bitstring float\",\"python bitstring split\",\"python int to bitstring\",\"python integer to bitstring\",\"python string as bitstring\",\"string to bitstring python\"],\"articleSection\":[\"How to\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-bitstring\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-bitstring\/\",\"name\":\"Python Bitstring: Classes and 6 Examples | Module - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png\",\"datePublished\":\"2020-08-04T19:38:26+00:00\",\"dateModified\":\"2021-06-14T10:07:26+00:00\",\"description\":\"Python Bitstring module has made it really easy or us to work with bits. We can convert strings, integer, bytes, hexadecimal into bitstrings.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-bitstring\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png\",\"width\":264,\"height\":159,\"caption\":\"python bitstring\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-bitstring\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Bitstring: Classes and 6 Examples | Module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\",\"name\":\"Ashwini Mandani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g\",\"caption\":\"Ashwini Mandani\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Bitstring: Classes and 6 Examples | Module - Python Pool","description":"Python Bitstring module has made it really easy or us to work with bits. We can convert strings, integer, bytes, hexadecimal into bitstrings.","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:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/","og_locale":"en_US","og_type":"article","og_title":"Python Bitstring: Classes and 6 Examples | Module","og_description":"Want to understand and work on the language which your computer and languages like python understand? Just go through this article one, we will help you","og_url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/","og_site_name":"Python Pool","article_published_time":"2020-08-04T19:38:26+00:00","article_modified_time":"2021-06-14T10:07:26+00:00","og_image":[{"width":264,"height":159,"url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png","type":"image\/png"}],"author":"Ashwini Mandani","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Ashwini Mandani","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#article","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/"},"author":{"name":"Ashwini Mandani","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056"},"headline":"Python Bitstring: Classes and 6 Examples | Module","datePublished":"2020-08-04T19:38:26+00:00","dateModified":"2021-06-14T10:07:26+00:00","mainEntityOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/"},"wordCount":854,"commentCount":0,"publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png","keywords":["bitstring module python","bitstring python","bitstring to bits python","convert hex string to bitstring python","print bitstring python formatte","python bitarray bitstring","python bitstring","python bitstring float","python bitstring split","python int to bitstring","python integer to bitstring","python string as bitstring","string to bitstring python"],"articleSection":["How to","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/","name":"Python Bitstring: Classes and 6 Examples | Module - Python Pool","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png","datePublished":"2020-08-04T19:38:26+00:00","dateModified":"2021-06-14T10:07:26+00:00","description":"Python Bitstring module has made it really easy or us to work with bits. We can convert strings, integer, bytes, hexadecimal into bitstrings.","breadcrumb":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#primaryimage","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png","contentUrl":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-3.png","width":264,"height":159,"caption":"python bitstring"},{"@type":"BreadcrumbList","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/python-bitstring\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python Bitstring: Classes and 6 Examples | Module"}]},{"@type":"WebSite","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#website","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/twitter.com\/pythonpool","https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056","name":"Ashwini Mandani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g","contentUrl":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g","caption":"Ashwini Mandani"}}]}},"_links":{"self":[{"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3825"}],"collection":[{"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=3825"}],"version-history":[{"count":9,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3825\/revisions"}],"predecessor-version":[{"id":13576,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3825\/revisions\/13576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/3833"}],"wp:attachment":[{"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=3825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=3825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=3825"}],"curies":[{"name":"wp","href":"https:\/\/web.archive.org\/web\/20240926034708\/https:\/\/api.w.org\/{rel}","templated":true}]}}