C Example: Base64 Codec: 3-byte blocks and padding rules
A from-scratch standard Base64 codec: packs every 3 bytes into 24 bits, splits them into four 6-bit indexes, and pads with = when fewer than 3 bytes remain. The decoder merges the indexes back and restores the exact byte count; three inputs verify the round trip.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
text : Hello, C! encoded : SGVsbG8sIEMh (12 chars) decoded : Hello, C! match : OK text : web-tutorial.com encoded : d2ViLXR1dG9yaWFsLmNvbQ== (24 chars) decoded : web-tutorial.com match : OK text : A encoded : QQ== (4 chars) decoded : A match : OK
🧩 Keep Learning