I have the following code:
var x = char.ConvertFromUtf32(0x0001F642);
var enc = new UTF32Encoding();
var bytes = enc.GetBytes(x);
var hex = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
if (i % 4 != 3)
continue;
hex.AppendFormat("{0:x2}", bytes[i - 0]);
hex.AppendFormat("{0:x2}", bytes[i - 1]);
hex.AppendFormat("{0:x2}", bytes[i - 2]);
hex.AppendFormat("{0:x2}", bytes[i - 3]);
}
var o = hex.ToString();
//results in 0001F642
This code tries to resolve the string which is in UTF-32 into hex decimal values, but I am facing the issue that the 4 Bytes representing the character are backwards. Is that a given or am I doing something wrong?
So without my i - 0, i - 1, i - 2, i - 3
and just formating the Byte Array as it is the result is
var x = char.ConvertFromUtf32(0x0001F642);
var enc = new UTF32Encoding();
var bytes = enc.GetBytes(x);
var hex = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
hex.AppendFormat("{0:x2}", bytes[i]);
}
var o = hex.ToString();
//results is 42f60100