Skip to main content
deleted 6 characters in body
Source Link
Klaus Gütter
  • 11.7k
  • 7
  • 33
  • 39

The string "0001F600""1F600" is the hexadecimal representation of a Unicode code point. As it is not in the BMP, you either need UTF32 or a UTF16 surrogate pair to represent it.

Here is some code to perform the requested conversion using UTF32 representation:

  1. Parse as 32-bit integer:

    var utf32Char = uint.Parse("0001F600""1F600", NumberStyles.AllowHexSpecifier);

  2. Convert this to a 4-element byte array in litte-endian byte order:

    var utf32Bytes = BitConverter.GetBytes(utf32Char);
    if (!BitConverter.IsLittleEndian)
        Array.Reverse(utf32Bytes);
    
  3. Finally, use Encoding.UTF32 to make a string from it.

    var str = Encoding.UTF32.GetString(utf32Bytes);
    Console.WriteLine(str);
    

The string "0001F600" is the hexadecimal representation of a Unicode code point. As it is not in the BMP, you either need UTF32 or a UTF16 surrogate pair to represent it.

Here is some code to perform the requested conversion using UTF32 representation:

  1. Parse as 32-bit integer:

    var utf32Char = uint.Parse("0001F600", NumberStyles.AllowHexSpecifier);

  2. Convert this to a 4-element byte array in litte-endian byte order:

    var utf32Bytes = BitConverter.GetBytes(utf32Char);
    if (!BitConverter.IsLittleEndian)
        Array.Reverse(utf32Bytes);
    
  3. Finally, use Encoding.UTF32 to make a string from it.

    var str = Encoding.UTF32.GetString(utf32Bytes);
    Console.WriteLine(str);
    

The string "1F600" is the hexadecimal representation of a Unicode code point. As it is not in the BMP, you either need UTF32 or a UTF16 surrogate pair to represent it.

Here is some code to perform the requested conversion using UTF32 representation:

  1. Parse as 32-bit integer:

    var utf32Char = uint.Parse("1F600", NumberStyles.AllowHexSpecifier);

  2. Convert this to a 4-element byte array in litte-endian byte order:

    var utf32Bytes = BitConverter.GetBytes(utf32Char);
    if (!BitConverter.IsLittleEndian)
        Array.Reverse(utf32Bytes);
    
  3. Finally, use Encoding.UTF32 to make a string from it.

    var str = Encoding.UTF32.GetString(utf32Bytes);
    Console.WriteLine(str);
    
Source Link
Klaus Gütter
  • 11.7k
  • 7
  • 33
  • 39

The string "0001F600" is the hexadecimal representation of a Unicode code point. As it is not in the BMP, you either need UTF32 or a UTF16 surrogate pair to represent it.

Here is some code to perform the requested conversion using UTF32 representation:

  1. Parse as 32-bit integer:

    var utf32Char = uint.Parse("0001F600", NumberStyles.AllowHexSpecifier);

  2. Convert this to a 4-element byte array in litte-endian byte order:

    var utf32Bytes = BitConverter.GetBytes(utf32Char);
    if (!BitConverter.IsLittleEndian)
        Array.Reverse(utf32Bytes);
    
  3. Finally, use Encoding.UTF32 to make a string from it.

    var str = Encoding.UTF32.GetString(utf32Bytes);
    Console.WriteLine(str);