User talk:Espeholt jr

UTF-16 Counted String
This wiki shows a counted-string method. Counted strings is in many ways better than null-terminated string.

Pros

 * Fast to determinated count of characters in string.
 * Fast to determinated count of total bytes in string.

Cons

 * A higher byte overdue than null-terminated string (up to 8 bytes compared to 1 byte but in most cases the overdue will be 2 bytes).
 * Can't contain a unlimited number of characters (but you will never use more than it can contain).

Bit table
At the start of a string is there 1 to 4 bytes which tells how long the string is. These is followed by 1 to 4 bytes which tells how many of the characters there is in plane 2. After these two groups of bytes the characters is represented.

Pseudo code to determinate count of characters
If Bit0 in Byte0 is 0 Count = Bit1 to Bit7 Else If Bit1 in Byte0 is 0 Count = Bit2 to Bit15 Else Count = Bit2 to Bit31

C code to determinate count of characters
int *p = (Start of bytes); int count;

if (*p & 0x80000000 == 0) count = *p & 0x7F000000; else if (*p & 0x40000000 == 0) count = *p & 0x3FFF0000; else count = *p & 0x3FFFFFFF;