In Java, Character.highSurrogate(codePoint) returns the high surrogate: the first of the two chars that encode a supplementary code point in UTF-16. For the emoji U+1F600 it returns '\uD83D'.
The high surrogate carries the upper 10 bits of codePoint - 0x10000, added to 0xD800. Its partner, lowSurrogate(), carries the lower 10 bits.
A static method of java.lang.Character (Java 7+): call it on the class, as in Character.highSurrogate(...); you do not need a Character object. No import is needed, because java.lang is always available.
Syntax
Pass a supplementary code point (0x10000 to 0x10FFFF).
Java
char a = Character.highSurrogate(0x1F600); // '\uD83D'
char b = Character.highSurrogate(0x10000); // '\uD800', the first high surrogate
char c = Character.highSurrogate(0x10FFFF); // '\uDBFF', the last one
// Character.highSurrogate('A') // unspecified result, do not do this
Call
What it does
Character.highSurrogate(cp)
First char of the pair.
Character.lowSurrogate(cp)
Second char of the pair.
(char) (((cp - 0x10000) >> 10) + 0xD800)
The same calculation by hand, for Java 6.
One overload, highSurrogate(int codePoint), added in Java 7. For both halves at once, toChars(cp) works on Java 5 and newer.
Library declarations
Java
// java.lang.Character (since Java 7)
public static char highSurrogate(int codePoint)
Parameters
Parameter
Description
codePoint (int)
A supplementary code point.
Return Value
Return Value
Description
char
A high surrogate from 0xD800 to 0xDBFF when the input is supplementary.