Conversion of decimal and hexadecimal in PHP

Source: Internet
Author: User
Tags integer numbers
{Code...} convert hexadecimal format $ s to decimal format and convert it back to hexadecimal format. There is a limit on the size of dechex () conversion. ------------ Supplement --------------------------------------- $ s & #039; 9C216AFB868C & #039; How does $ s add 1php ?...
$s = '9C216AFB868C';$sb=hexdec($s) ;var_dump( $sb );//1.716673427227E+14echo '
';var_dump( dechex($sb) );//6afb868c

Convert the hexadecimal value $ s to the decimal value, and then convert the hexadecimal value to the hexadecimal value.

Querydechex()The conversion size is limited.
------------ Supplement ---------------------------------------
$ S = '9c216afb868c ';
How is it implemented in $ s plus 1 php? (Hexadecimal calculation)

Reply content:
$s = '9C216AFB868C';$sb=hexdec($s) ;var_dump( $sb );//1.716673427227E+14echo '
';var_dump( dechex($sb) );//6afb868c

Convert the hexadecimal value $ s to the decimal value, and then convert the hexadecimal value to the hexadecimal value.

Querydechex()The conversion size is limited.
------------ Supplement ---------------------------------------
$ S = '9c216afb868c ';
How is it implemented in $ s plus 1 php? (Hexadecimal calculation)

The final output result can be compared.6afb868cExactly9C216AFB868C(Case Insensitive ).

In the hexdec manual ,:

Starting from PHP 4.1.0, this function can process large integer numbers. In this case, it will return the float type.

In dechex:

The maximum value to be converted is decimal.PHP_INT_MAX * 2 + 1(Or-1): On a 32-bit platform, the decimal value is 4294967295, and the result of dechex () isFfffffff.

First result1.716673427227E+14Common Format171667342722700, There is no problem with this result.

9c216afb868cTo decimal: http://www.wolframalpha.com/input? I = convert ++ 9c216afb868c + to + base + 10

This number is converted back to Yes9c216afb868c.

171667342722700Turn hexadecimal: http://www.wolframalpha.com/input? I = 171667342722700 + to + hex

First, if you are not a 32-bit computer, the number of digits is far from the maximum number that PHP can handle. The maximum value in PHP can be a constant.PHP_INT_MAXThe value of the 64-bit computer is

echo PHP_INT_MAX;    // 9223372036854775807echo dechex(PHP_INT_MAX); // 7fffffffffffffff

Besides, you can switch from hexadecimal to hexadecimal.It's impossible to go back because of the size problem.. The problem lies in the 10 hexadecimal value you transferred out. It is

1.716673427227E+14

This isString represented by scientific notation, AnddechexThe function cannot recognize this string,In php, only strings composed of numbers are automatically converted to corresponding integer or floating point values..

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.