Decimalsystem conversion function description, decimalsystem_PHP tutorial-php Tutorial

Source: Internet
Author: User
Tags binary to decimal decimal to binary
Description of the decimalsystem conversion function, decimalsystem. Description of the decimalsystem conversion function, decimalsystem 1, decimalsystem conversion function description 1, decimalsystem to binary decbin () function, the following example shows the echo decimal system conversion function description, decimalsystem

1. description of the decimal system conversion function
1. decimal to binary decbin () function, as shown in the following example:

Echo decbin (12); // output 1100
Echo decbin (26); // output 11010
Decbin
(PHP 3, PHP 4, PHP 5)
Decbin -- Convert decimal to binary
Description
String decbin (int number)
Returns a string containing the binary representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is a string of 32 characters.

2. decimal to octal decoct () function

Echo decoct (15); // output 17
Echo decoct (264); // output 410
Decoct
(PHP 3, PHP 4, PHP 5)
Decoct -- Convert decimal to octal
Description
String decoct (int number)
Returns a string containing the octal representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is 37777777777 ".

3. decimal to hexadecimal dechex () function

Echo dechex (10); // output
Echo dechex (47); // output 2f
Dechex
(PHP 3, PHP 4, PHP 5)
Dechex -- Convert decimal to hexadecimal
Description
String dechex (int number)
Returns a string containing the hexadecimal representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is "ffffffff ".

II. binary system conversion functions
1, binary to hexadecimal to bin2hex () function

$ Binary = "11111001 ";
$ Hex = dechex (bindec ($ binary ));
Echo $ hex; // output f9
Bin2hex
(PHP 3> = 3.0.9, PHP 4, PHP 5)
Bin2hex -- Convert binary data to hexadecimal representation
Description
String bin2hex (string str)
Returns an ASCII string in hexadecimal notation of the str parameter. The byte mode is used for conversion. the byte level is higher than the byte level.

2. Convert binary to decimal bindec () function

Echo bindec ('20140901'); // output 51
Echo bindec ('20140901'); // output 51
Echo bindec ('20140901'); // output 7
Bindec
(PHP 3, PHP 4, PHP 5)
Bindec -- Convert binary to decimal
Description
Number bindec (string binary_string)
Returns the decimal value of the binary number represented by the binary_string parameter.
Bindec () converts a binary number to an integer. The maximum number of convertible values is 31-bit 1 or decimal 2147483647. PHP 4.1.0 starts. This function can process large numbers. in this case, it returns the float type.

III. description of octal system conversion functions
Octal to decimal Dec () function

Echo octdec ('77 '); // output 63
Echo octdec (decoct (45); // output 45
Octdec
(PHP 3, PHP 4, PHP 5)
Octdec -- convert octal to decimal
Description
Number octdec (string octal_string)
Returns the decimal equivalent of the octal value represented by the octal_string parameter. The maximum convertible value is 17777777777 or 2147483647 in decimal format. PHP 4.1.0 starts. This function can process large numbers. in this case, it returns the float type.

IV. description of the hexadecimal (hexadecimal) conversion function
Hexadecimal to decimal hexdec () function

Var_dump (hexdec ("See "));
Var_dump (hexdec ("ee "));
// Both print "int (238 )"

Var_dump (hexdec ("that"); // print "int (10 )"
Var_dump (hexdec ("a0"); // print "int (160 )"
Hexdec
(PHP 3, PHP 4, PHP 5)
Hexdec -- Convert hexadecimal to decimal
Description
Number hexdec (string hex_string)
Returns the decimal number equivalent to the hexadecimal number indicated by the hex_string parameter. Hexdec () converts a hexadecimal string to a decimal number. The maximum value to be converted is 7 fffffff, that is, 2147483647 of the decimal number. PHP 4.1.0 starts. This function can process large numbers. in this case, it returns the float type.
Hexdec () replaces all non-hexadecimal characters with 0. In this way, all the zeros on the left are ignored, but the zeros on the right are included.

5. Any hexadecimal conversion base_convert () function

$ Hexadecimal = 'a37334 ';
Echo base_convert ($ hexadecimal, 16, 2); // output 101000110111001100110100
Base_convert
(PHP 3> = 3.0.6, PHP 4, PHP 5)

Base_convert -- convert a number between any hexadecimal values
Description
String base_convert (string number, int frombase, int tobase)
Returns a string containing the number in tobase format. The number is specified by frombase in hexadecimal notation. Both frombase and tobase can only be between 2 and 36 (including 2 and 36 ). Numbers higher than decimal digits are represented by the letter a-z. for example, a represents 10, B represents 11, and z represents 35.

Here, we mainly sort out the PHP hexadecimal conversion functions to facilitate development and search. for details about the functions, see The PHP Manual. Please pay attention to the next series of Chinese character encoding studies.


JavaScript or PHP code that converts a decimal number to a hexadecimal number

JavaScript decimal to other hexadecimal codes: var m = 10; document. write (m. toString (2) +"
"); // Display as 1010 binary document. write (m. toString (8) +"
"); // Display as a 12-8 hexadecimal document. write (m. toString (10) +"
"); // Display as 10 decimal document. write (m. toString (16) +"
"); // Display as a. The hexadecimal php conversion function is as follows: bindec ()-binary conversion to decimal
Decbin ()-decimal to binary
Dechex ()-Convert decimal to hexadecimal
Decoct ()-decimal to octal
Hexdec ()-hexadecimal conversion to decimal
Octdec ()-octal to decimal
Base_convert ()-converts numbers in any expected hexadecimal format as follows: 1. description of the decimal system conversion function
1. Convert decimal to binary decbin () function, as shown in the following example echo decbin (12); // output 1100
Echo decbin (26); // output 11010
Decbin
(PHP 3, PHP 4, PHP 5)
Decbin -- Convert decimal to binary
Description
String decbin (int number)
Returns a string containing the binary representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is a string of 32 characters. 2. Convert decimal to octal decoct () function echo decoct (15); // output 17
Echo decoct (264); // output 410
Decoct
(PHP 3, PHP 4, PHP 5)
Decoct -- Convert decimal to octal
Description
String decoct (int number)
Returns a string containing the octal representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is 37777777777 ". 3. Convert decimal to hexadecimal: dechex () function echo dechex (10); // output
Echo dechex (47); // output 2f
Dechex
(PHP 3, PHP 4, PHP 5)
Dechex -- Convert decimal to hexadecimal
Description
String dechex (int number)
Returns a string containing the hexadecimal representation of the given number parameter. The maximum value to be converted is 4294967295 in decimal format, and the result is "ffffffff ". II. binary system conversion functions
1. binary to hexadecimal bin2hex () function $ binary = "11111001 ";
$ Hex = dechex (bindec ($ binary ));
Echo $ hex; // output f9
Bin2hex
(PHP 3> = 3.0.9, PHP 4, PHP 5)
Bin2hex -- add the full text of... to the rest>

Question about hexadecimal conversion functions

Package com. test. numsys;

Import java. util .*;

/**
* Convert numeric values to Decimal binary octal hexadecimal
*/
Public class NumSys {

Public static void main (String [] args ){

NumSys ns = new NumSys ();
System. out. println ("Convert decimal 100 to binary:" + ns. decimalToBinary (100); // 1100100

System. out. println ("Convert binary 1100100 to octal:" + ns. binaryToOctal (1100100); // 144

System. out. println ("Convert binary 10110000011101 to hexadecimal:" + ns. binaryToHex ("10110000011101"); // 2C1D

System. out. println ("decimal 100 to octal:" + ns. DecimalToOctal (100 ));

System. out. println ("Convert decimal 15400 to hexadecimal:" + ns. DecimalToHex (15400 ));
}

// The decimal part is not converted to binary.
Public long decimalToBinary (int ){

Long binary = 0L;
Int [] binaryArr = new int [64];
Int I = 0;
Do {
BinaryArr [I] = a % 2;
A = a/2;
I ++;
} While (! = 0 );

String s = "";
For (int j = binaryArr. length-1; j> = 0; j --){
S + = binaryArr [j] + "";
}

Binary = Integer. parseInt (s );

Return binary;
}

// Convert binary to octal
Public String binaryToOctal (long ){
String octal = "";
String s = a + "";
Char [] c_temp = (a + ""). toCharArray ();

Int temp = 3-c_temp.length % 3;
For (int I = 0; I S = "0" + s;
}

Char [] c2 = s. toCharArray ();
List List = new ArrayList ();

For (int I = 0; I <c2.length; I + = 3 ){
String stemp = c... the remaining full text>

Description of Transform (decimal system) function, decimalsystem 1, decimal system conversion function description 1, decimal to binary decbin () function, the following example echo...

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.