Skip to content

Instantly share code, notes, and snippets.

@aliostad
Created January 18, 2015 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliostad/e9e0cad7386a95c57401 to your computer and use it in GitHub Desktop.
Save aliostad/e9e0cad7386a95c57401 to your computer and use it in GitHub Desktop.
Turns UTF-8 hex representation of the character to its Unicode code in Little Endian
var hex = "d8a7";
var utf8 = Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
var s = Encoding.UTF8.GetString(utf8);
var uni = Encoding.Unicode.GetBytes(s);
Console.WriteLine("0x" + string.Join("", uni.Reverse().Select(x => x.ToString("X"))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment