int given base 2 and then hex:

>>> int('010110', 2)
22
>>> hex(int('010110', 2))
'0x16'
>>> 

>>> hex(int('0000010010001101', 2))
'0x48d'

The doc of int:

int(x[, base]) -> integer

Convert a string or number to an integer, if possible.  A floating

point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. If base is zero, the proper base is guessed based on the string content. If the argument is outside the integer range a long object will be returned instead.

The doc of hex:

hex(number) -> string

Return the hexadecimal representation of an integer or long

integer.

Answer from Eli Bendersky on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-convert-binary-to-hexadecimal
Python Program to Convert Binary to Hexadecimal - GeeksforGeeks
July 23, 2025 - ... # Python code to convert binary ... to hexadecimal def binToHexa(n): bnum = int(n) temp = 0 mul = 1 # counter to check group of 4 count = 1 # char array to store hexadecimal number hexaDeciNum = ['0'] * 100 # counter for hexadecimal ...
Discussions

python - Convert hex to binary - Stack Overflow
I have ABC123EFFF. I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes). How? More on stackoverflow.com
🌐 stackoverflow.com
Code to convert from binary to hexadecimal
Posted by u/No_Ingenuity9213 - 2 votes and 3 comments More on reddit.com
🌐 r/Python
3
2
February 28, 2022
Unexpected result trying to convert hex to binary
Note what bin(int('1', 16)) alone gives. 0b, similarly to 0x with a hex representation, is use to indicate the base of the representation of the number (b for binary here). More on reddit.com
🌐 r/learnpython
11
2
October 5, 2021
How to convert a String to hex and calculate binary result in python
Based on this I convert each char to the hex-equivalent: 0x31, 0x44, 0x68 and subtract 0x30; so I get 0x1, 0x14, 0x38; In the next step I have to convert to the binary equivalent 000001, 010100, 111000 and merge this to 000001010100111000. From this I want to get the integer meaning, in this case 5432. Is there a possibility to do this in a smart and easy way in python... More on mindstick.com
🌐 mindstick.com
0
January 27, 2015
🌐
Note.nkmk.me
note.nkmk.me › home › python
Convert Binary, Octal, Decimal, and Hexadecimal in Python | note.nkmk.me
May 19, 2023 - Built-in Functions - format() — Python 3.11.3 documentation · You can convert a number to a binary, octal, or hexadecimal string by specifying b, o, or x in the format specification string, which is used as the second argument of format().
🌐
Exercism
exercism.org › tracks › python › concepts › binary-octal-hexadecimal
Binary, Octal, and Hexadecimal in Python on Exercism
Ready to put your newfound language skills into use? Get 40% off CodeCrafter's real-world proficiency projects! ... Binary, octal, and hexadecimal (also known as hex) are different numeral systems with different bases. Binary is base 2, octal is base 8, and hexadecimal is base 16. Normal integers are base 10 in python...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-hex-into-binary
Python - Ways to convert hex into binary - GeeksforGeeks
July 12, 2025 - For example a = "1A3" we need to convert it to binary so that resultant output should be 110100011. We can convert hexadecimal to binary by first converting it to an integer using int() and then using the bin() function.
Find elsewhere
🌐
Reddit
reddit.com › r/python › code to convert from binary to hexadecimal
r/Python on Reddit: Code to convert from binary to hexadecimal
February 28, 2022 - this code is kinda messy but ignore that def Hexdecimal_conv(a): if a == ["0", "0", "0", "0"]: return "0" if a == ["0", "0", "0", "1"]: return '1' if…
🌐
Quora
quora.com › How-can-I-convert-binary-to-hex-in-Python
How to convert binary to hex in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Teleport
goteleport.com › home › resources › tools › hex to binary converter | instantly convert hex to binary numbers
Hex to Binary Converter | Instantly Convert Hex to Binary Numbers | Teleport
While ubiquitous in computing, hexadecimal's compact form can be challenging to interpret and work with directly. Binary notation provides a more fundamental and unambiguous representation, connecting hexadecimal's abstraction to the underlying 0s and 1s that drive digital systems.
🌐
Python
docs.python.org › 3 › library › binascii.html
binascii — Convert between binary and ASCII
Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation.
🌐
Reddit
reddit.com › r/learnpython › unexpected result trying to convert hex to binary
r/learnpython on Reddit: Unexpected result trying to convert hex to binary
October 5, 2021 -
print(bin(int('1', 16)).zfill(32))

The above command MOSTLY works but for some reason my output is thus:

000000000000000000000000000000b1

Any clue as to why the 'b' is there? oddly enough it "floats" around depending on what number I input, always being as high as possible, causing ValueErrors when close to the biggest number

🌐
Caesar Cipher
caesarcipher.org › overview › learn › converters › hex to binary conversion: complete guide with table & examples
Hex to Binary Conversion: Complete Guide with Table & Examples
March 18, 2026 - Hex-to-binary conversion is a foundational skill built on one simple rule: each hex digit equals exactly 4 binary bits. Whether you are converting a single digit like A (1010), a byte like FF (11111111), or a complex value like DEADBEEF, the process is always the same mechanical substitution.
🌐
Quora
quora.com › How-do-you-convert-hex-to-binary-in-the-form-of-string-Python-solutions
How to convert hex to binary in the form of string (Python, solutions) - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Hex-Rays
hex-rays.com › ida-free
IDA Free: Disassembler & Decompiler at No Cost
Free disassembler and decompiler to learn reverse engineering. Core IDA features at no cost for students and non-commercial use. Download and start today.
🌐
GitHub
gist.github.com › 64f4255278a8fa2a33876b6c946669c6
Hex and Binary Python · GitHub
To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters · Show hidden characters · Raw · Hex_and_Binary.md · There are two python programs in this gist · The first one is binary_letters.py ·
🌐
Reddit
reddit.com › r › softwarearchitecture › new
r/softwarearchitecture
December 23, 2013 - Sitting and reading a spec before approving? Not bad. Maybe 2 or 3 in a day so you have time to verify the models work before you send it off to your perfectly-tuned, highly context-scoped, former-{... meta, FB, Netflix} Principal of Principal Engineers Mega-Agent (I've seen .mds \w 1000+ lines).
🌐
MindStick
mindstick.com › forum › 12905 › how-to-convert-a-string-to-hex-and-calculate-binary-result-in-python
How to convert a String to hex and calculate binary result in python – MindStick
January 27, 2015 - Based on this I convert each char to the hex-equivalent: 0x31, 0x44, 0x68 and subtract 0x30; so I get 0x1, 0x14, 0x38; In the next step I have to convert to the binary equivalent 000001, 010100, 111000 and merge this to 000001010100111000. From this I want to get the integer meaning, in this case 5432. Is there a possibility to do this in a smart and easy way in python?
🌐
Medium
rjallain.medium.com › understanding-binary-and-hexadecimal-numbers-by-writing-python-code-f7c4012fafe7
Understanding Binary and Hexadecimal Numbers by Writing Python Code | by Rhett Allain | Medium
July 8, 2023 - I’m going to show how to convert from binary to decimal (and back) and then the same for hexadecimal. Although you can use built in functions in python, we are going to write some code mostly from scratch (because it will be fun).
🌐
LabEx
labex.io › tutorials › python-how-to-work-with-hex-representations-502160
How to work with hex representations | LabEx
When working in LabEx's Python environment, remember that: ... ## Hex bitwise AND operation a = 0x0F ## Binary: 00001111 b = 0x3C ## Binary: 00111100 result = a & b ## Bitwise AND print(hex(result)) ## Outputs: 0xc