DEV Community

dss99911
dss99911

Posted on • Originally published at dss99911.github.io

Encoding and Base64

Encoding

Why Encode Data?

Encoding prevents invalid values during transmission (communication can have various issues with cookies, etc.)

Example: Base64 in Android

result = Base64.encodeToString(bytes, Base64.NO_WRAP);
Enter fullscreen mode Exit fullscreen mode

Why Use Base64?

Use Cases

  1. Converting binary data to text

    • When you need to handle binary data as text
  2. Storing binary in databases

    • Databases often cannot store raw binary values directly
    • Convert binary to text format
  3. Embedding images in HTML

    • Include images directly without external links (inline images)

When to Use Base64

  1. Not needed when:

    • Both sides have same encoding/decoding rules
    • Data is already binary (like images)
    • Start and end of binary data is clear
  2. Required for:

    • Data managed by humans (DBMS, Excel, etc.)
    • Binary data must be represented as ASCII
  3. For different character sets:

    • Use BASE64/HEX as intermediate format to transfer binary data between systems with different character sets

Reference


Originally published at https://dss99911.github.io

Top comments (0)