Updated bitwise logic for all alphabets