Conversion between hexadecimal

Source: Internet
Author: User

Conversion between hexadecimal

Our computer stores binary values, which can also be converted by php. In this case, we can tell you in a simple way that this blog is just a note for study.

10 to others (2, 8, 16)

Rule: decimal number, divided by the target base. The remainder and operator are obtained. If the operator is not zero, continue to divide the operator by the target system to obtain the remainder and operator. Until the operator is zero, connect all the remainder from the bottom to the bottom:


$ Int = 1234;
// 10 to 8
// 1234
// 8
// 154 2
// 8
// 19 2
// 8
// 2 3
// 8
// 0 2
//
//

Convert others (, 16) to 10

Rule: Use the number on each digit, multiplied by the power of the weight in the forward order, so that the result can be accumulated.

Weight, starting from the low position to 0, in turn + 1 to the high position;


/// 10 to 16
// 1234
// 16
// 77 2
// 16
// 4 13 (D)
// 16
// 0 4
//
// 16 to 10
// Weight: 210
// 4D2
// 4*16 ^ 2 + D * 16 ^ 1 + 2*16 ^ 0
// = 4*256 + 13*16 + 2*1
// = 1024 + 208 + 2 = 1234
//
// 8 to 10
// 3210
// 2322
// 2*8 ^ 3 + 3*8 ^ 2 + 2*8 ^ 1 + 2*8 ^ 0

In the program, the hexadecimal conversion function:

Dec, 10

Bin, 2

Oct, 8

Hex, 16

Decbin (); 10to2

Dechex (); 10 to 16

Octdec (); 8 to 10

For example:

Function parameters, which are expected to be strings.


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.