Skip to content

Instantly share code, notes, and snippets.

View aranjello's full-sized avatar

Andrew Goodman aranjello

View GitHub Profile
@aranjello
aranjello / utf-8ToInt.c
Created November 1, 2021 22:58
Simple converter from utf-8 unicode character to its corresponding decimal value
int getDecimalOfUtf8(char * utfPointer){
int outPut = utfPointer[0]; //sets the final output number to the value of the first byte of the utf-8 code
int numStarting1 = 0; //tracks number of 0's at beggining of character to see if utf-8
while ((utfPointer[0] << numStarting1 & 0x80) ? 1 : 0) //shifts bits of first byte of utfPointer and checks if the MSB is 1 or 0
{
numStarting1++; //increments numStarting1
}
//At this point numStarting1 could be returned to know the length in bytes of the unicode character