Skip to content

Instantly share code, notes, and snippets.

@devhawk
Created June 15, 2022 20:22
Show Gist options
  • Save devhawk/e66c49e5d3ff9acd4af5466f79b54d25 to your computer and use it in GitHub Desktop.
Save devhawk/e66c49e5d3ff9acd4af5466f79b54d25 to your computer and use it in GitHub Desktop.
static int GetLength(ReadOnlyMemory<char> base64)
{
if (base64.IsEmpty) return 0;
var characterCount = base64.Length;
var paddingCount = 0;
if (base64.Span[characterCount - 1] == '=') paddingCount++;
if (base64.Span[characterCount - 2] == '=') paddingCount++;
return (3 * (characterCount / 4)) - paddingCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment