How to Convert an Octal Escape Sequence in Python – And Vice Versa?

This tutorial will show you how to convert an But let’s quickly recap what an octal escape sequence is in the first place! πŸ‘‡ What Is An Octal Escape Sequence?πŸ’‘ An Octal Escape Sequence is a backslash followed by 1-3 octal digits (0-7) such as \150 which encodes the ASCII character ‘h’. Each octal escape … Read more

Python Binary String to ASCII String – and Vice Versa

Problem Formulation In this article, you’ll learn how to convert binary string (values) to an ASCII string in Python. For example, you may want to convert the binary string: 0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100 to the ASCII text: hello world Using a simple Python script! πŸ’¬ Question: How would we write Python code to perform the binary to ASCII … Read more

Python Convert Hex to Base64

πŸ’¬ Question: How to convert a hexadecimal string such as 02af01ff00 to a normal string using the Base64 format in Python? πŸ‘‰ Short answer: Use the following fancy one-liner expression to convert the hex string s to a Base64-encoded Python string: base64.b64encode(bytes.fromhex(s)).decode(). For the long answer, keep reading! πŸ₯Έ If you’re like me, you may … Read more

3 Easy Habits That Can Make You Rich as a Freelance Coder

In this article, I’ll show you three simple habits to get way more done, have a much easier and stress-free life, and make more money. Almost guaranteed. Based on science! But there’s a catch: these habits are often tough to implement for employees. I know because I have been there and done that. When I finally created … Read more

How to Write to a Binary File in Python?

Problem Formulation πŸ’¬ Question: Given a binary string in your Python script, such as b’this is a binary string’. How to write the binary string to a file in Python? For example, you may have tried a code snippet like this that will not work with file.write(): Because this yields a TypeError: Traceback (most recent … Read more

How to Write a Hex String as Binary Data & Binary File in Python?

Hex String as Binary Data To convert a hex string such as ‘FF0001AF’ to binary data, use the binascii.unhexlify(hex_str) function that returns the binary data represented by the hexadecimal string. Note that this converts two hex string digits to one byte, i.e., hex string ‘F0’ is converted to the byte representation 11110000, or in binary … Read more

Python Hex String to Big Endian (Bytes/Integer)

What Is Big/Little Endian? Computers perform computations on data that is represented with bytes, i.e., sequences of 0s and 1s. A computer program manipulates data by loading data from memory (RAM, Cache, Disk, SSD), performing computations based on that data, and storing the resulting data back into the memory. A computer program loads and stores … Read more