I used the -r and -p switches for xxd:

$ echo '0006303030304e43' | xxd -r -p | nc -l localhost 8181

Thanks to inspiration from @Gilles' answer, here's a Perl version:

$ echo '0006303030304e43' | perl -e 'print pack "H*", <STDIN>' | nc -l localhost 8181
Answer from Chris Snow on Stack Exchange
🌐
Code Beautify
codebeautify.org › hex-string-converter
Hex to String Converter Online to Convert Hex to Text
Upside Down Text Letter Randomizer NTLM Hash Generator Password Generator Random Words Generator Text Minifier Word Repeater String Builder Intelligent Message Filter Word Replacer Reverse String Text Reverser HTML Encode HTML Decode Base32 Encode Base32 Decode Base58 Encode Base58 Decode Base64 Encode Base64 Decode URL Encode URL Decode String to Hex Converter Hex to String Converter String to Binary Converter Binary to String Converter Case Converter Delimited Text Extractor Remove Punctuation Remove Accents Remove Duplicate Lines Remove Empty Lines Remove Line Breaks Remove Extra Spaces Remove Whitespace Remove Lines Containing Sort Text Lines Text to ROT13 ROT13 to Text Calculate String Length Text Flipper Text Replacer
Discussions

python - Convert hex to binary - Stack Overflow
Return the binary data represented by the hexadecimal string specified as the parameter. ... This returns "binary" as in the actual bytes, but it does not convert it to a printable representation as "0" and "1". More on stackoverflow.com
🌐 stackoverflow.com
java - Convert hexadecimal string (hex) to a binary string - Stack Overflow
The above method basically takes each character in the Hex string and converts it to its binary equivalent pads it with zeros if necessary then joins it to the return value. Is this a proper way of performing a conversion? More on stackoverflow.com
🌐 stackoverflow.com
Help needed C, hex string to binary string.
Assuming that you only have to convert hex to binary, the simplest approach would be to simply map hex characters to sets of binary characters: Hex | Binary ----+------- 0 | 0000 1 | 0001 2 | 0010 3 | 0011 4 | 0100 5 | 0101 6 | 0110 7 | 0111 8 | 1000 9 | 1001 a | 1010 b | 1011 c | 1100 d | 1101 e | 1110 f | 1111 Then you merely have to iterate through the hex string, fetch the binary string that corresponds with the current hex character, and append that to the tentative binary string. You could store the mapping shown in the table as either a dictionary, an array (with some algebra to convert the hex characters to array indices), or a series of if statements (not recommended -- poor form, but might be sufficient for an extreme beginner class). EDIT: To use an example, converting 4f into binary, you'd see that 4 in hex is 0100 in binary and add that to the (currently empty) tentative binary string. Then the next hex character is f, which is 1111 in binary. Append that to our tentative string and we have 01001111. And that's our answer. More on reddit.com
🌐 r/learnprogramming
7
1
April 3, 2014
How to convert a hexadecimal string to a binary string in C - Stack Overflow
That way you'll get the number value of a hex digit, but you won't get the binary representation. Also, to do such a lookup, i'd either use a fixed string (0123456789abcdef) and then get the value of a digit by using strchr() on it or i'd just use an array char [256] and use the character/digit ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
Binary expands these strings, providing a more transparent view of the underlying data structure. Bitwise Operations: Working directly with binary is essential for performing bitwise operations, such as masking, shifting, and logical operations. Low-Level Programming: Interacting with hardware and memory often involves working with binary data. Converting hexadecimal to binary allows for more precise manipulation and understanding of these low-level values.
Top answer
1 of 16
160

For solving the left-side trailing zero problem:


my_hexdata = "1a"

scale = 16 ## equals to hexadecimal

num_of_bits = 8

bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)

It will give 00011010 instead of the trimmed version.

2 of 16
90

Convert hex to binary

I have ABC123EFFF.

I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).

Short answer:

The new f-strings in Python 3.6 allow you to do this using very terse syntax:

>>> f'{0xABC123EFFF:0>42b}'
'001010101111000001001000111110111111111111'

or to break that up with the semantics:

>>> number, pad, rjust, size, kind = 0xABC123EFFF, '0', '>', 42, 'b'
>>> f'{number:{pad}{rjust}{size}{kind}}'
'001010101111000001001000111110111111111111'

Long answer:

What you are actually saying is that you have a value in a hexadecimal representation, and you want to represent an equivalent value in binary.

The value of equivalence is an integer. But you may begin with a string, and to view in binary, you must end with a string.

Convert hex to binary, 42 digits and leading zeros?

We have several direct ways to accomplish this goal, without hacks using slices.

First, before we can do any binary manipulation at all, convert to int (I presume this is in a string format, not as a literal):

>>> integer = int('ABC123EFFF', 16)
>>> integer
737679765503

alternatively we could use an integer literal as expressed in hexadecimal form:

>>> integer = 0xABC123EFFF
>>> integer
737679765503

Now we need to express our integer in a binary representation.

Use the builtin function, format

Then pass to format:

>>> format(integer, '0>42b')
'001010101111000001001000111110111111111111'

This uses the formatting specification's mini-language.

To break that down, here's the grammar form of it:

[[fill]align][sign][#][0][width][,][.precision][type]

To make that into a specification for our needs, we just exclude the things we don't need:

>>> spec = '{fill}{align}{width}{type}'.format(fill='0', align='>', width=42, type='b')
>>> spec
'0>42b'

and just pass that to format

>>> bin_representation = format(integer, spec)
>>> bin_representation
'001010101111000001001000111110111111111111'
>>> print(bin_representation)
001010101111000001001000111110111111111111

String Formatting (Templating) with str.format

We can use that in a string using str.format method:

>>> 'here is the binary form: {0:{spec}}'.format(integer, spec=spec)
'here is the binary form: 001010101111000001001000111110111111111111'

Or just put the spec directly in the original string:

>>> 'here is the binary form: {0:0>42b}'.format(integer)
'here is the binary form: 001010101111000001001000111110111111111111'

String Formatting with the new f-strings

Let's demonstrate the new f-strings. They use the same mini-language formatting rules:

>>> integer = 0xABC123EFFF
>>> length = 42
>>> f'{integer:0>{length}b}'
'001010101111000001001000111110111111111111'

Now let's put this functionality into a function to encourage reusability:

def bin_format(integer, length):
    return f'{integer:0>{length}b}'

And now:

>>> bin_format(0xABC123EFFF, 42)
'001010101111000001001000111110111111111111'    

Aside

If you actually just wanted to encode the data as a string of bytes in memory or on disk, you can use the int.to_bytes method, which is only available in Python 3:

>>> help(int.to_bytes)
to_bytes(...)
    int.to_bytes(length, byteorder, *, signed=False) -> bytes
...

And since 42 bits divided by 8 bits per byte equals 6 bytes:

>>> integer.to_bytes(6, 'big')
b'\x00\xab\xc1#\xef\xff'
🌐
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.
🌐
RapidTables
rapidtables.com › convert › number › hex-to-binary.html
Hex to Binary Converter
Binary number example: 11012 = 1×23+1×22+0×21+1×20 = 1310 · Convert every hex digit (start lowest digit) to 4 binary digits, with this table:
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-hex-into-binary
Python - Ways to convert hex into binary - GeeksforGeeks
July 12, 2025 - a = "1A3" # Convert hexadecimal to an integer d = int(a, 16) # Convert integer to binary using bin() b = bin(d)[2:] # Remove the "0b" prefix print("Binary:", b) ... format(int(a, 16), 'b') converts integer to a binary string without "0b" prefix ...
🌐
Binary Hex Decimal Converter
binaryhexconverter.com › hex-to-binary-converter
Hexadecimal to Binary Converter
Hexadecimal to binary converter helps you to calculate binary value from a hex number up to 16 characters length, and hex to bin conversion table.
🌐
StrongDM
strongdm.com › tools › hex-to-binary-converter
Hex to Binary Converter: Online & Free [No Sign-Up]
1. Enter Input: Paste a hexadecimal string (e.g., 48656C6C6F) or binary string (e.g., 01001000 01100101) into the text box. ... – Click “Hex to Binary” to convert hex to 8-bit spaced binary.
🌐
Reddit
reddit.com › r/learnprogramming › help needed c, hex string to binary string.
r/learnprogramming on Reddit: Help needed C, hex string to binary string.
April 3, 2014 -

Learning C currrently could use a little help. I'm still new to programming so the simpler the better.

So I'm having a lot of difficulty wrapping my head around this problem.

I'm trying to write a function that will convert a hexadecimal string (0123456789abcdef) into binary (0000 0001 .......).

Been stuck for several hours trying to figure out a solution. Any help will be greatly appreciated.

🌐
Tomeko
tomeko.net › online_tools › hex_to_file.php
Hex to file (binary) converter
Create arbitrary file from hexadecimal code (javascript, client-side only).
🌐
Magic Tool
magictool.ai › tool › hex-to-binary
Hex to Binary Converter
Convert Hex to Binary and Binary to Hex online. Hex to Binary Converter instantly translates hex code to binary and vice versa.
🌐
Code Beautify
codebeautify.org › hex-binary-converter
Best Hex to Binary Converter Online tool
This tool allows loading the Hex URL, which loads Hexadecimal and converts to Binary Numeral System.
🌐
NI Community
forums.ni.com › community › discussion forums › most active software boards › labview › how to convert hexadecimal string to binary
how to convert Hexadecimal string to binary - NI Community
February 21, 2006 - Converting to a different string is easy: Use "Scan from string" to convert your hex string to a number and "Format into string" to get a boolean string. The format codes are "%x" and "%b", respectively. You can also use the intermediate number to convert to a boolean array.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Hexadecimal string to binary - Programming - Arduino Forum
June 22, 2017 - Hi guys, I need to convert a hexadecimal string to a binary in order to extract specific bits from it. I receive a character line by a serial port, and i separate the hexadecimal code in a string. I have to "reverse" i…
🌐
SCADACore
scadacore.com › home › tools › programming calculators › online hex converter
Online Hex Converter - Bytes, Ints, Floats, Significance, Endians - SCADACore
April 8, 2021 - Hex-To-UINT (Unsigned Integer) and Hex-To-INT (Singed Integer) Converts the Hex string to the 4 different Endian Combinations.
🌐
PHP
php.net › manual › en › function.hex2bin.php
PHP: hex2bin - Manual
Returns the binary representation of the given data or false on failure. If the hexadecimal input string is of odd length or invalid hexadecimal string an E_WARNING level error is thrown.