PHP: detailed description of ord ($ str) & amp; gt; 0x80 _ PHP Tutorial

Source: Internet
Author: User
PHP detailed description of ord ($ str) & amp; gt; 0x80. The GBK simplified character set is encoded in 1 and 2 bytes at the same time. When the high position is 0x00 ~ 0x7f is a byte. if the value is greater than 0x80, two bytes are used for representation. note: the GBK simplified character set encoding in the brackets is expressed by one or two bytes at the same time. When the high position is 0x00 ~ 0x7f is a byte, and the value above 0x80 is expressed in two bytes"

Note: The brackets are in hexadecimal format.

When you find that the content of a byte is greater than 0x7f, it must be a Chinese character (pieced together with another byte). how can you determine whether it must be greater than 0x7f?
The number next to 0x7f (1111111) is 0x80 (10000000), so if you want to exceed 0x7f, the maximum bit of this byte must be 1, we only need to determine whether the highest bit is 1.

Judgment method:

Bits and (the same bits are 1 and only 1; otherwise, 0 ):
For example, to determine whether the third digit of a number is 1, as long as it is connected to 4 (100) bits, to determine whether the third digit of a number is 1 is 2 (10) bits and 2 (10) bits.
Similarly, judge whether the eighth digit is 1 as long as it matches (10000000), that is, 0x80 and so on.

Why not> 0x7f? php may be okay, but in other strong languages, the maximum bit of one byte is used to indicate a negative number. a negative number cannot be greater than 0x7f (the largest integer)

Another example:
The assic code of a is 97 (1100001)
The assic code of A is 65 (1000001)

B's assic code is 98 (1100010)
B's assic code is 66 (1000010)

We found a rule: a lowercase letter, the sixth character must be 1. we can use this to determine the case:
At this time, we only need to use a letter with 0x20 (100000) to position and judge:

The code is as follows:


If (ord ($ a) & 0x20 ){
// Uppercase
}


How can I change all letters to uppercase letters? Change 1 of the sixth digit to 0:

The code is as follows:


$ A = 'a ';
$ A = chr (ord ($ )&(~ 0x20 ));
Echo $;

Bytes. When the high position is 0x00 ~ 0x7f is a byte, and the value above 0x80 is expressed in two bytes. note: inside the brackets...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.