This code will not work properly:
else if (str[i] >> 6 == 2)
because for non-ascii char the value will actually be negative. For bitshift operation char will be promoted to negative int with all 3 upper bytes having all their bits set to 1. So the result will be some large value, not 2.
This code will work:
else if (((str[i] >> 6) & 0x3) == 2)
Bit mask is your friend ;)
This code will not work properly: else if (str[i] >> 6 == 2) because for non-ascii char the value will actually be negative. For bitshift operation char will be promoted to negative int with all 3 upper bytes having all their bits set to 1. So the result will be some large value, not 2. This code will work: else if (((str[i] >> 6) & 0x3) == 2) Bit mask is your friend ;)