user67600: How to convert Unicode char to "Unicode HEX Position" in Arduino or C
i will share a picture here :

for example in JavaScript you can do that with charCodeAt(); ! this function will return exactly the char-code and then you can convert it to hex!
for example in JavaScript i can do that like this to return exact table value
 var inpString = 'س';
    var myChar=0;
    var output = 0;
    myChar = inpString.charCodeAt(0);
    output = (ToHex((myChar&0xff00)>>8 )) + (ToHex( myChar&0xff ));
    
    function ToHex(i)
    {
        var sHex = "0123456789ABCDEF";
        var Out = "";
        Out = sHex.charAt(i&0xf);
        i>>=4;
        Out = sHex.charAt(i&0xf) + Out;
        return Out;
    }
 alert(output);


So how can i do that in Arduino ? its using to send unicode char in PDU mode in Arduino
i just need to convert unicode char like this -> 'س' to correct Unicode HEX Position that i shared in the picture above
for example 'س' is 0633 or 'A' is 0041 or 'ب' is 067E

user7508: Unlike JavaScript, C++ makes no difference between a character and its
code point. Thus, 'A', 0x41 and 65 are just different ways of
writing the same number.
Note, however, that the char type is intended to hold ASCII only. For
everything else, you may try using wide characters. For example, the
program
void setup() {
    Serial.begin(9600);
    wchar_t c = L'س';
    Serial.println(c, 16);
}

void loop() {}

outputs 633 on the serial port. Note the second argument to
Serial.println() which specifies base 16. Default is to print
numbers in decimal.
Beware that the representation of wide characters is implementation
defined, and the avr-libc doesn't provide support for manipulating them
or strings made with them. If you want to transmit them, you will also
have to decide for yourself how to break them down into a sequence of
bytes, as that's the only thing a serial port (or I2C, or SPI for that
matter) can transmit. UTF-8 is the most popular choice. I doubt wide
characters are popular in embedded systems at all.

67600: <p>How to convert Unicode char to &quot;Unicode HEX Position&quot; in Arduino or C</p>
<p>i will share a picture here :</p>
<p><a href="https://i.stack.imgur.com/YCKAH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YCKAH.png" alt="enter image description here" /></a></p>
<p>for example in JavaScript you can do that with <code>charCodeAt();</code> ! this function will return exactly the char-code and then you can convert it to hex!</p>
<p>for example in JavaScript i can do that like this to return exact table value</p>
<pre><code> var inpString = 'س';
    var myChar=0;
    var output = 0;
    myChar = inpString.charCodeAt(0);
    output = (ToHex((myChar&amp;0xff00)&gt;&gt;8 )) + (ToHex( myChar&amp;0xff ));
    
    function ToHex(i)
    {
        var sHex = &quot;0123456789ABCDEF&quot;;
        var Out = &quot;&quot;;
        Out = sHex.charAt(i&amp;0xf);
        i&gt;&gt;=4;
        Out = sHex.charAt(i&amp;0xf) + Out;
        return Out;
    }
 alert(output);

</code></pre>
<p>So how can i do that in Arduino ? its using to send unicode char in PDU mode in Arduino
i just need to convert unicode char like this -&gt; 'س' to correct Unicode HEX Position that i shared in the picture above</p>
<p>for example 'س' is 0633 or 'A' is 0041 or 'ب' is 067E</p>
 7508: <p>Unlike JavaScript, C++ makes no difference between a character and its
code point. Thus, <code>'A'</code>, <code>0x41</code> and <code>65</code> are just different ways of
writing the same number.</p>
<p>Note, however, that the <code>char</code> type is intended to hold ASCII only. For
everything else, you may try using <a href="https://en.wikipedia.org/wiki/Wide_character" rel="nofollow noreferrer">wide characters</a>. For example, the
program</p>
<pre class="lang-cpp prettyprint-override"><code>void setup() {
    Serial.begin(9600);
    wchar_t c = L'س';
    Serial.println(c, 16);
}

void loop() {}
</code></pre>
<p>outputs <code>633</code> on the serial port. Note the second argument to
<code>Serial.println()</code> which specifies base 16. Default is to print
numbers in decimal.</p>
<p>Beware that the representation of wide characters is implementation
defined, and the avr-libc doesn't provide support for manipulating them
or strings made with them. If you want to transmit them, you will also
have to decide for yourself how to break them down into a sequence of
bytes, as that's the only thing a serial port (or I2C, or SPI for that
matter) can transmit. UTF-8 is the most popular choice. I doubt wide
characters are popular in embedded systems at all.</p>
