Skip to content

Instantly share code, notes, and snippets.

@decay88
Created March 3, 2020 06:03
Show Gist options
  • Save decay88/6a8c04cf76696ab7471ce9134f551e24 to your computer and use it in GitHub Desktop.
Save decay88/6a8c04cf76696ab7471ce9134f551e24 to your computer and use it in GitHub Desktop.
Encoding.cs
public static string ToString(this byte[] bytes)
{
char[] chars = new char[bytes.Length / sizeof(char)];
Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
return new string(chars);
}
public static byte[] ToByteArray(this string @string)
{
byte[] bytes = new byte[@string.Length * sizeof(char)];
Buffer.BlockCopy(@string.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment