Base64 Integer

Turn an unsigned decimal into the Base64 of its bytes, or the other way.

A whole number as bytes

Some APIs store an integer as the Base64 of its big-endian bytes, not as the Base64 of the decimal digits. This page converts an unsigned integer to that Base64, or reads the bytes back to decimal. Encoding the characters themselves is Base64.

How to use it

  1. Enter the number or the Base64. Update as you type is on.
  2. Mode is Decimal to Base64 or Base64 to decimal.
  3. Convert runs once. Show Example sets Decimal to Base64 and 256. The result is AQA=, the bytes 01 00. 255 is /w==. 0 is AA==, one zero byte.
  4. Clear All empties both boxes. Copy Result copies the output.

How the bytes are chosen

Decimal to Base64 accepts digits only. A minus sign, a decimal point, spaces and a leading plus are rejected. The integer is written in hexadecimal, padded to an even number of digits, then those bytes are standard Base64. The only leading zero is that padding, so 0 is a single 00 byte. Base64 to decimal reads standard Base64, treats the bytes as an unsigned big-endian integer, and prints decimal. Empty Base64 is an error. Extra leading 00 bytes do not change the decimal value.

Where people use it

  • Matching a counter that was stored as Base64 bytes.
  • Checking that 256 is AQA=, not the Base64 of the characters 2, 5 and 6.
  • Reading a short binary id back to a number.

Questions

Base64 of the text 256 is different.

That encodes the characters. This page encodes the integer 256 as the bytes 01 00.

A negative number failed.

Only unsigned integers. There is no sign byte.