Friday, July 25, 2025

Understanding RAD50 Encoding in Embedded Systems

When working on embedded systems like Arduino, every byte of memory can matter. This is especially true when storing lots of short text, such as identifiers, filenames, or codes. That's where an old but clever technique called RAD50 encoding can help.

What is RAD50?

RAD50 is a way to compress 3 characters into 2 bytes. Normally, storing 3 characters in ASCII takes 3 bytes. But RAD50 packs those same characters into just 2 bytes, saving space. This works only for a limited set of characters, mostly uppercase letters, digits, and a few symbols.

How does it work?

RAD50 uses a math trick. Instead of storing each character separately, it treats the group of 3 characters as a single number using base-40 arithmetic. Here's the idea:

  • Each character is given a number from 0 to 39.

  • The first character is multiplied by 40 squared.

  • The second is multiplied by 40.

  • The third is added directly.

  • The result is a single number that fits within 16 bits (2 bytes).

When decoding, the process is reversed to get the original 3 characters back.

So you're not slicing bits per character. You're just combining values in a smart way that compresses the text into less space.

Why would you use RAD50?

You'd consider RAD50 in embedded systems if:

  • You're storing a lot of short text, like tags or codes.

  • You want to save RAM, EEPROM, or flash memory.

  • Your text only uses uppercase letters, numbers, and a few basic symbols.

  • You don’t need international characters or lowercase letters.

In these cases, RAD50 can reduce memory usage by about 33 percent. That means more data fits in the same space — and that can be a big deal on microcontrollers with limited memory.

When is RAD50 not a good idea?

RAD50 isn’t helpful if:

  • You need to store lowercase letters or special characters.

  • You're working with human-readable text or full sentences.

  • You need simple string handling — RAD50 adds encoding and decoding overhead.

Final Thoughts

RAD50 is a clever old-school trick that's still useful today — especially in tight memory environments where you need to pack as much information as possible. It's not for every project, but when you’re dealing with limited character sets and memory pressure, it's a neat tool to keep in your embedded toolbox.

No comments:

Post a Comment