Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does this char string related piece of C++ code do?

bool check(const char *text) {
    char c;
    while (c=*text++) {
        if ((c&0x80)&&((*text) & 0x80)) {
            return true;
        }
    }
    return false;
}

What’s 0x80 and the what does the whole mysterious function do?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

rewriting to be less compact

   while (true)
   {
       char c = *text;
       text += 1;
       if (c=='\0') // at the end of string?
          return false;
       int temp1 = c & 0x80; // test MSB of c
       int temp2 = (*text) & 0x80; // test MSB of next character
       if(temp1 != 0 && temp2 != 0) // if both set the return true
          return true;
    }

MSB means Most Significant Bit. Bit7. Zero for plain ascii characters

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading