PHP detailed ASCII code comparison and character conversion _php tips

Source: Internet
Author: User
Tags comparison table control characters ord
One, common ASCII code comparison


illustration of an ASCII comparison chart , taking character A as an example
Dec means decimal, such as 65
HX represents hexadecimal, such as 41
Oct represents octal, such as 101
Char represents a display character, such as a

ASCII code comparison chart is divided into two units
1, control characters 0-31 and 127
2, can display the character 32-126
(1) 48~57 is 0 to 90 Arabic numerals;
(2) 65~90 is 26 uppercase letters;
(3) The 97~122 number is 26 lowercase English letters;
(4) Other punctuation marks, operation symbols, etc.;

Two, ASCII expansion code Comparison table


Three, PHP character conversion function description

Specific character conversion function description please refer to [PHP function chapter in decimal, Binary, octal and 16 conversion function description]
Decimal binary Decbin () function
Decimal spin octal decoct () function
Decimal hexadecimal Dechex () function
Binary turn 16 Bin2Hex () function
Binary Turn 10 Bindec () function
Octal decimal octdec () function
Hexadecimal decimal hexdec () function
Arbitrary-transform Base_convert () function

Character Conversion instances
instance one , how to convert a character to binary, octal, or hexadecimal, you can use the Ord () function to convert a character to an ASCII value, and then convert it using the corresponding feed conversion function, as follows
A this character is converted to binary/eight/16, as follows
The decimal of a character: Ord (' a '); Output 97
Binary: Decbin (Ord (' A ')); Output 1100001
Octal system: Decoct (Ord (' A ')); Output 141
Hex: Dechex (Ord (' A ')); Output 61

It can then be checked by the output of each input corresponding to the above ASCII code comparison chart.

example two , how to convert a binary to a binary of 16 or a decimal, such as a binary, as follows
Using instance one to get binary of a character
Decbin (Ord (' A '));
Then convert the binary to 16 or decimal
Hex: Bin2Hex (Decbin (Ord (' A '));//Output 31313030303031
Binary J:bindec (ord (' A ')) (Decbin); Output 97

The Ord () function discussed above is discussed in detail in the next issue of the text Encoding Research series.

Iv.. Reference materials
PHP functions in decimal, binary, octal and 16 conversion function description
Asciitable Comparison Chart
Wikipedia ASCII
Baidu Encyclopedia ASCII

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.