Q:

Writing unicode characters in XeLaTeX using \char

I want to print some characters using the \char command. The Unicode is 2b45. I have already tried the code \char"2b45 but it prints some illegal character and b45. Variations with braces also don't work. Does anyone have any idea about this? I have also tried other variations, but they also print the same thing.

A:

As Joseph Wright and others have said in the comments, you need uppercase letters with \char, so \char"2B45.
There are other options as well.  The LaTeX command \symbol{"2B45} is essentially equivalent to \char, and will always display the character at slot #x2B45 of the current font.  The escape sequence ^^^^2b45 (which breaks the pattern by taking lowercase letters) is equivalent to entering the Unicode character ⭅ (U+2B45).  If that character is active, this form will trigger the code for it.
Here is an extremely artificial example of how you might use both, to define a symbol that generates the math symbol in math mode, with correct operator spacing, or a symbol in text mode that matches the current text formatting.
Note that the first argument to \newunicodechar should be the Unicode character itself, and it should generate a command to select the correct font and display the symbol from it.
\tracinglostchars=2 % Print a warning if a character is missing.
\documentclass{book}
\usepackage{newunicodechar}
\usepackage{unicode-math} % Or another package with \LLeftarrow, such as stix2
\usepackage[paperwidth=10cm]{geometry} % Solely to format a MWE on TeX.SX

\defaultfontfeatures{Scale=MatchLowercase}
\setmathfont{STIX Two Math}
\newfontfamily\symbolfamily{STIX Two Math}[
  BoldFont = *,
  BoldFeatures = {FakeBold = 1.05},
  SlantedFont = *,
  SlantedFeatures = {FakeSlant = 0.25},
  BoldSlantedFont = *,
  BoldSlantedFeatures = {FakeBold = 1.05, FakeSlant = 0.25}
]

\newunicodechar{^^^^2b45}% ⭅
{\ifmmode\LLeftarrow% In math-mode, use the math symbol
\else{\symbolfamily\symbol{"2B45}}% In text mode, change the font family
\fi}

\begin{document}
The ⭅ symbol can be used in math mode as \(a ⭅ b\).  If we had a full font family
containing this glyph, we could write it as \textbf{bold ⭅},
\textsl{slanted ⭅}, or {\bfseries\slshape both ⭅}.
\end{document}

A:

Some more words to complement Davislor's fine answer.
Using \char is not the best way to cope with the problem to begin with, because TeX will ignore a following space character. On the other hand, \symbol wouldn't.
Try \char"2B45 is nice and you'll see no space. It will be there with
\symbol{"2B45} is nice

If you want to always input the hexadecimal code and not bother with uppercase and lowercase, you can define a wrapper:
\documentclass{article}
\usepackage{fontspec}

\setmainfont{EB Garamond}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\uni}{O{12}m}
 {
  \char_generate:nn { \int_from_hex:n { #2 } } { #1 }
 }

\ExplSyntaxOff

\begin{document}

The character \uni{2b45} is nice and so is \uni{2B46}.

\end{document}

The optional argument (default 12) can be used to generate a character with a different category code, in case of need.

