What’s a prefix code?

Print anything with Printful



Prefix codes use binary code to represent letters and characters, with binary trees used to translate them. This reduces the amount of storage space required, with single bits used for frequently occurring characters and multiple bits for infrequent ones. Binary trees can increase storage space by up to 50%.

A prefix code is the binary code structure that represents certain letters or characters. These strings of code are used by computers to communicate. They consist of zeros and ones that translate into certain commands or words. For example, the letter “A” may contain a 0 prefix while the number 1010 represents the letter “D”.

Binary trees are used to represent how the strings of numbers in the prefix code translate into certain letters, characters or messages. Many software applications use a binary tree-based prefix code to compress their data. Different combinations of binary code are merged into a single “tree” which can contain one or more messages. There is usually a root which is represented by a 0 or 1 which is equated to one of the characters.

From the root, an extension of numbers can be followed which translates into another letter. There may be several branches stemming from the main line of the binary tree that result in separate characters. Letters or characters that are represented by one binary digit are called single bits, while those that are represented by multiple binary digits are called two, three, or four bits.

The number of bits is directly related to the number of binary digits representing a particular character in a prefix code. Single bits are typically used for characters that occur multiple times in a message, while strings of two or more bits are used for letters and characters that occur infrequently. For example, if a prefix code encodes the word “relentless”, a single bit will most likely represent the letter “E”.

Words and messages are usually created by stringing together a binary code that reads from left to right of the prefix code tree. For example, a binary tree may contain the letter “R” which is represented by the binary digit 0, the letter “E” which is represented by the binary string 011, and the letter “D” which is represented by the binary string 0110. In this case the word “red” would be put together as 00110110.

Using prefix codes, computers and applications are able to save space. Since a number of commands and messages use the same letters and characters, each can be represented by certain translations of binary code. Separately, these words may require additional storage space due to the amount of bits each of them contains. Binary trees reduce the amount of bits required, sometimes increasing storage space by up to 50%.




Protect your devices with Threat Protection by NordVPN


Skip to content