Original PHP: binary, octal, hexadecimal, and mutual computing

Source: Internet
Author: User
Tags decimal to binary
Original PHP: binary, octal, hexadecimal, and mutual computing

In the previous chapter, binary, octal, hexadecimal, and reciprocal calculation are one,

This article focuses on the mutual calculation between binary, octal, and hexadecimal, and how to convert the binary into decimal.

How can we convert decimal to binary, octal or hexadecimal?

In fact, it is very simple. if you want to convert it to binary, divide the decimal number by 2 until the quotient is 0, and then obtain the remainder value first.

After sorting, you can get the value above and put it together.

How about converting decimal to octal ?, Just change the divisor to eight,

Hexadecimal format? That must have changed the divisor to sixteen.

Next we will explain in detail

  • Convert decimal to binary

Convert a decimal number of 11 to binary. the calculation procedure is as follows:

Expression quotient remainder

11 Jun 2 5 1

5 then 2 2 1

2 bytes 2 1 0

1 limit 2 0 1

Finally, we sorted the result in the descending order as 1011. how is it easy?

  • Convert decimal to octal

Decimal number 17 to octal. calculation procedure

Expression quotient remainder

17 listen 8 2 1

2 bytes 8 0 2

Finally, we sorted the result in the descending order as 021. how is it easy?

  • Convert decimal to hexadecimal

Convert the decimal number 22 to the hexadecimal format. the calculation procedure is as follows:

Expression quotient remainder

22 Jun 16 1 6

1 limit 16 0 1

Finally, we sorted the result in the descending order as 0 × 16. how is this simple?

This is the end ..

In fact, it is very easy to get into the number.

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.