Fundamentals 13 min read

Unlocking Data: How Bits, Bytes, Hex and Encoding Shape Everything

This article explains the relationships between bits, binary, hexadecimal, bytes and strings, shows how computers store and process data using binary, demonstrates hexadecimal and Base64 encodings, provides conversion tables and examples, and clarifies how UTF‑8 encodes characters.

Lin is Dream
Lin is Dream
Lin is Dream
Unlocking Data: How Bits, Bytes, Hex and Encoding Shape Everything

The article discusses the relationship between bits, binary, hexadecimal, bytes and strings, and explains common terminology such as HEX (hexadecimal), DEC (decimal), OCT (octal) and BIN (binary).

Binary (binary) encoding

Origin of information – Computers store all information (text, images, audio, video, keys, encrypted results, etc.) as binary data (0 and 1). Eight bits form a byte, and encoding tables such as ASCII or UTF‑8 translate between human‑readable characters and binary.

Storage and representation of binary data :

Byte – A byte (8 bits) can represent 256 different values (0‑255).

Byte string – A sequence of bytes represents a string, file or other data. For example, the character A is 01000001, occupying one byte.

Encoding format – Different encodings (ASCII, UTF‑8, UTF‑16, etc.) define how characters are converted to bytes.

Hexadecimal (Hex) encoding

Hexadecimal represents each byte as a two‑digit hex number (0‑F). A byte is split into two 4‑bit groups, each shown as a hex digit. The prefix 0x indicates hexadecimal. Hex is widely used for debugging, viewing raw file bytes, and representing keys or certificates.

Hexadecimal representation of binary data

Binary data is often shown in hexadecimal because each two hex characters correspond to one byte (8 bits), making long binary sequences easier to read.

Relationship between hex and binary :

Binary consists of 0 and 1; every 4 bits map to one hex digit.

One hex digit represents 4 bits (a nibble), so two hex digits represent one byte.

Hexadecimal and binary conversion

30 82 01 0a 02 82 01 01 …

– each pair of hex characters equals one byte (8 bits). 30

0011 0000
82

1000 0010
01

0000 0001
0a

0000 1010 A 256‑bit key in binary would be extremely long, while its hexadecimal form ( 30 82 01 0a …) is much shorter and easier to understand.

Base64 representation of binary data

Base64 encodes binary data into an ASCII string using 64 printable characters (A‑Z, a‑z, 0‑9, +, /). Every 3 bytes become 4 characters, increasing size by about 33 %.

Character set – 64 characters as described above.

Output length – 4 characters for every 3 bytes of input.

Use cases – Common for transmitting keys, certificates, signatures, images, etc., in text‑only environments.

Hex‑binary conversion table

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

Example: hex 30 corresponds to binary 0011 0000.

Character data to binary (UTF‑8 encoding)

Characters are encoded to binary according to their Unicode code points. ASCII characters use one byte; non‑ASCII characters use multiple bytes.

Character 'A' → Unicode U+0041 → binary 01000001 (1 byte).

Character '中' → Unicode U+4E2D → UTF‑8 bytes 11100100 10111000 10101101 (3 bytes).

String str = "中";
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
for (byte b : bytes) {
    System.out.printf("%8s ", Integer.toBinaryString(b & 0xFF).replace(' ', '0'));
    System.out.printf("0x%02X ", b);
}

Resulting binary for "A中" is 01000001 11100100 10111000 10101101.

Binary data to character data (UTF‑8 decoding)

UTF‑8 uses leading bytes to indicate the total number of bytes in a character (e.g., 110xxxxx for 2‑byte, 1110xxxx for 3‑byte, 11110xxx for 4‑byte). Continuation bytes start with 10. This allows the decoder to reconstruct characters correctly.

1‑byte characters: 0xxxxxxx (ASCII).

2‑byte characters: 110xxxxx 10xxxxxx.

3‑byte characters: 1110xxxx 10xxxxxx 10xxxxxx.

4‑byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx.

How many English letters fit in 4 KB?

1 KB = 1024 bytes. 4 KB = 4096 bytes. Assuming ASCII encoding (1 byte per letter), 4 KB can store 4096 English letters.

Binary and decimal conversion

Positive integers: repeatedly divide by 2 and collect remainders in reverse order. Negative integers: convert the absolute value, invert bits, then add 1 (two's complement). Example: IP address 192.168.1.200 → binary 11000000.10101000.00000001.11001000.

Conclusion

The article clarified the relationships among bits, binary, hexadecimal, bytes and strings, providing a solid foundation for understanding data representation in computing.

encodingUTF-8FundamentalsBase64Binaryhexadecimaldata representation
Lin is Dream
Written by

Lin is Dream

Sharing Java developer knowledge, practical articles, and continuous insights into computer engineering.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.