Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are 4 bytes characters represented in C#

How are 4 bytes chars are represented in C#? Like one char or a set of 2 chars?

var someCharacter = 'x'; //put 4 bytes UTF-16 character
like image 917
SiberianGuy Avatar asked Oct 20 '11 09:10

SiberianGuy


People also ask

How many characters are 4 bytes?

There are 2,097,152 possible 4-byte characters, but not all of them are valid and not all of the valid characters are used. This chart shows selected groups of 4-byte characters, including emojis, symbols, and Egyptian hieroglyphs.

How are 4 bytes int stored?

Integers are commonly stored using a word of memory, which is 4 bytes or 32 bits, so integers from 0 up to 4,294,967,295 (232 - 1) can be stored.


1 Answers

C# can only store characters from the Basic Multilingual Plane in the char type. For characters outside this plane two chars must be used - called surrogates.

You can also use a string literal such as:

string s = "\U0001D11E";

See UTF-16.

like image 170
Mark Byers Avatar answered Oct 14 '22 17:10

Mark Byers