# When is Unicode code point same as Mathematica CharacterCode?

For what characters c does CharacterCode[c] not return the same value as c's Unicode code point? How does one convert c to its Unicode code point with Mathematica in general?

You can see here.

For a character in range U+0000 to U+D7FF or U+E000 to U+FFFF, ToCharacterCode[c] will just return the same value as c's Unicode code point.

For a character in range U+10000 to U+10FFFF, ToCharacterCode[c] will return two numbers, and Mathematica will take it as two characters.

For example:

In:= ToCharacterCode /@ {"\$", "€", "𐐷", "𤭢"}

Out= {{36}, {8364}, {55297, 56375}, {55378, 57186}}

In:= StringLength@"𐐷"

Out= 2


In fact, the Unicode code point of "𐐷" is U+10437, which is 66615 in decimal. And {55297, 56375} is just IntegerDigits[66615 - 65536, 1024] + {55296, 56320}.

The following function can convert a Unicode code point to the corresponding Mathematica CharacterCode.

If[# < 65536, {#}, IntegerDigits[# - 65536, 1024] + {55296, 56320}] &

• What about the characters between U+D7FF and U+E000? – qazwsx Mar 19 '15 at 2:07
• @qazwsx They are not assigned to characters. – alephalpha Mar 19 '15 at 2:21
• 55296 is 0xD800. What's 56320? – qazwsx Mar 19 '15 at 3:57
• @qazwsx 0xDC00. – alephalpha Mar 19 '15 at 5:50
• I know, but why 0xDC00? – qazwsx Mar 20 '15 at 1:45