PHP detailed description of ord ($ str) & gt; 0x80
Source: Internet
Author: User
To identify double-byte characters, such as Chinese characters or Japanese and Korean characters, each byte occupies 1 high. Generally, Chinese and Japanese characters only have one byte and are effectively encoded by seven characters, the binary code corresponding to a high value of 0 and 0x80 is 10000000, and the highest bit is one, representing Chinese characters. the Chinese character encoding format is generally referred to as the GBK simplified character set encoding, which is expressed by 1 byte and 2 byte 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:
Copy codeThe 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:
Copy codeThe code is as follows:
$ A = 'a ';
$ A = chr (ord ($ )&(~ 0x20 ));
Echo $;
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.