Another way to do this is by using the bitstring module:

>>> from bitstring import BitArray
>>> input_str = '0xff'
>>> c = BitArray(hex=input_str)
>>> c.bin
'0b11111111'

And if you need to strip the leading 0b:

>>> c.bin[2:]
'11111111'

The bitstring module isn't a requirement, as jcollado's answer shows, but it has lots of performant methods for turning input into bits and manipulating them. You might find this handy (or not), for example:

>>> c.uint
255
>>> c.invert()
>>> c.bin[2:]
'00000000'

etc.

Answer from Alex Reynolds on Stack Overflow
🌐
GIGACalculator.com
gigacalculator.com › converters › data › bytes to bits converter
Bytes to Bits Converter - Convert Bytes to Bits
This is the basis for the ASCII ... to 01100001 in the ASCII table. To convert from bytes to bits you only need to multiply by 8....
🌐
GB to KB Conversion
gbmb.org › home › bits conversion
Bits to Bytes Conversion
1 Bit is equal to (1/8) × 100-0 Bytes. 1 Bit = (1/8) × 100 Bytes. 1 Bit = (1/8) × 1 Bytes. 1 b = 0.125 B. There are 0.125 Bytes in a Bit. Bit (b) is a measurement unit used in binary system to store or transmit data, like internet connection speed or the quality scale of an audio or a video ...
🌐
GB to KB Conversion
gbmb.org › home › bytes conversion
Bytes to Bits Conversion
1 byte consists of 8 bits, which go together as one unit in storage, processing or transmission of digital information. Byte is the unit of data Unit symbol of byte is B (uppercase) 1 byte = 8 bits · Bit (b) is a measurement unit used in binary system to store or transmit data, like internet ...

Another way to do this is by using the bitstring module:

>>> from bitstring import BitArray
>>> input_str = '0xff'
>>> c = BitArray(hex=input_str)
>>> c.bin
'0b11111111'

And if you need to strip the leading 0b:

>>> c.bin[2:]
'11111111'

The bitstring module isn't a requirement, as jcollado's answer shows, but it has lots of performant methods for turning input into bits and manipulating them. You might find this handy (or not), for example:

>>> c.uint
255
>>> c.invert()
>>> c.bin[2:]
'00000000'

etc.

Answer from Alex Reynolds on Stack Overflow
🌐
CheckYourMath
checkyourmath.com › convert › digital_storage › bytes_bits.php
Convert Bytes to bits - Digital Storage Conversions (Binary)
There are 0.125 Bytes in a bit. A bit is a unit used to measure digital storage and is based on "Binary multiples of bits". The symbol for bit is b.
🌐
Wikipedia
en.wikipedia.org › wiki › Byte
Byte - Wikipedia
2 days ago - In this era, bit groupings in the instruction stream were often referred to as syllables or slab, before the term byte became common. The modern de facto standard of eight bits, as documented in ISO/IEC 2382-1:1993, is a convenient power of two permitting the binary-encoded values 0 through ...
Find elsewhere
🌐
GIGACalculator.com
gigacalculator.com › converters › data › bits to bytes converter
Bits to Bytes Converter - Convert Bits to Bytes
Both the bit and the byte are data units used for measuring data storage capacity and transmission capacity (bandwidth). The only difference between the two is that a byte is 8 times larger than a bit. A bit is the smallest possible amount of ...
🌐
DEV Community
dev.to › acroynon › bits-bytes-and-binary-4d8h
Bits, Bytes, and Binary - DEV Community
November 19, 2019 - For example, hundred, thousand, million, etc. A singular binary digit, a single 0 or 1, is referred to as a bit. 8 bits are called a byte, so two bytes would be 16 bits in two groups of 8.
🌐
Kyle's Converter
kylesconverter.com › kyle's converter › data storage › bytes › bytes to megabytes (binary)
Bytes to Megabytes (binary) | Kyle's Converter
Converts from Bytes for you! Instantly Converts Bytes to Megabytes (binary) and Many More Data Storage Conversions Online. Bytes Conversion Charts. Many Other Conversions.
🌐
Inch Calculator
inchcalculator.com › home › conversion › data storage › bytes › bytes to bits
Bytes to Bits Converter (B to b) - Inch Calculator
May 9, 2025 - Bytes can be abbreviated as B; for example, 1 byte can be written as 1 B. You can use our binary calculator to convert a number of bits to other number systems such as hex or decimal.
🌐
Medium
medium.com › basecs › bits-bytes-building-with-binary-13cb4289aafa
Bits, Bytes, Building With Binary | by Vaidehi Joshi | basecs | Medium
January 3, 2019 - Two bytes means 16 bits (binary digits), which means that you can represent 65,536 different combinations (2 to the power of 16)! That’s a whole lot of different permutations that you can represent with just 2 bytes!
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-bytes-to-bits-in-python
Convert Bytes To Bits in Python - GeeksforGeeks
July 23, 2025 - This method counts the number of 1 bits in each byte of the byte sequence by converting each byte to its binary form and counting the occurrences of 1 using a generator expression and bin(byte).count('1').
🌐
Cryptii
cryptii.com › pipes › text-to-binary
Text to binary: Encode and convert text to bytes - cryptii
Computers store instructions, texts and characters as binary data. All Unicode characters can be represented solely by UTF-8 encoded ones and zeros (binary numbers). Find out what your data looks like on the disk.
🌐
CheckYourMath
checkyourmath.com › convert › digital_storage › bits_bytes.php
Convert bits to Bytes - Digital Storage Conversions (Binary)
A Byte is a unit used to measure digital storage and is based on "Binary multiples of Bytes". The symbol for Byte is B.
🌐
Medium
daviddecoding.medium.com › know-your-bits-and-bytes-406942418c05
Know your Bits and Bytes. Low level programming guide to… | by David De | Medium
March 18, 2024 - The most important reason for choosing 8 bits, instead of anything else, is that it can be represented as 2^power. So the above 2 bytes can represent the decimal numbers 102 (0110 0110 in Binary) and 255 (1111 1111 in Binary).
🌐
Google Play
play.google.com › store › apps › details
Bits Bytes Binary Converter - Apps on Google Play
June 14, 2024 - With this tool you can: · Convert Bits/Bytes (Kilo, Mega, Giga, Tera, Peta). · Convert Binary/Decimal and Decimal/Binary. · Calculate download time for a file. Entering the size of a file, the connection speed, will show you the transfer rate and the time needed for its download.
🌐
Quora
quora.com › How-do-you-convert-bits-to-bytes-and-kilobytes
How to convert bits to bytes and kilobytes - Quora
Answer (1 of 6): For Bits to Bytes Conversion: 1 Byte = 8 Bits Therefore, 1 Bit = 1/8 Bytes, by using this relation we can convert bits to bytes. To convert bits to bytes, just multiply the value in bits by 1/8. For Bits to Kilobytes Conversion: 1 KiloByte = 8192 Bits Therefore, 1 Bit = 1/8...
🌐
Carnegie Mellon University
cs.cmu.edu › ~fgandon › documents › lecture › uk1999 › binary › HandOut.pdf pdf
Bit, Byte, and Binary Number of bits Number of values 2 raised to the power
bits used to represent each dot. A 1-bit image is monochrome; an 8-bit image supports 256 colors or grayscales; and a 24- or 32-bit ... nibble: Half a byte – four bits. Nibbles are important in hexadecimal and BCD representations. The term is sometimes spelled nybble. byte: Abbreviation for binary term, a unit of storage capable of holding a single character.
🌐
Stanford
web.stanford.edu › class › cs101 › bits-bytes.html
Bits and Bytes
Text is quite compact, using few bytes, compared to images etc. One byte works well for individual characters, but computers are also good at manipulating numbers. Integers are typically stored with either 4 or 8 bytes 4 bytes can store numbers between -2147483648 and 2147483647 8 bytes can store numbers between -9223372036854775808 and 9223372036854775807 · Adding in binary is just like normal addition with carrying But when you run out of bits you can't carry anymore Leftmost bit indicates sign, so carrying to the leftmost bit changes a number ffrom positive to negative.