> For the complete documentation index, see [llms.txt](https://www.ctfrecipes.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.ctfrecipes.com/cryptography/general-knowledge/encoding/data-encoding/base16.md).

# Base16

**Base16**, also known as **hexadecimal encoding**, is a binary-to-text encoding scheme that represents binary data as a sequence of 16 characters (**0-9** and **A-F**).

## How it works ?

Hexadecimal encoding works by dividing the binary data into 4-bit blocks and then representing each block as a character in a predefined set of 16 characters.

This results in a representation that is more compact than the original binary data, making it easier to store or transmit.

To encode binary data as Base16, each group of 4 bits is converted to its corresponding hexadecimal character, and the characters are concatenated to form the final encoded string.

To decode Base16-encoded data, the reverse process is performed, converting each hexadecimal character back into its corresponding 4-bit binary representation and concatenating the results.

## Python

```python
data = b"SomeData"

hexData = data.hex()

decoded = bytes.fromhex(hexData)
```
