Convert decimal to binary

Source: Internet
Author: User
Tags decimal to binary

One integer

If the integer is divided by 2, the quotient is further divided by 2, and 0 is obtained, the remainder is sorted in reverse order.

Take 22 as an example:
22/2 11 + 0
11/2 5 + 1
5/2 2 + 1
2/2 more than 1 0
1/2 more than 0 1
So the binary value of 22 is 10110.


Decimal
Multiply the decimal number by 2, and then the decimal part by 2. Then, the decimal part is rounded up to 0, and the integers are arranged in order.

Take 0.8125 as an example:
0.8125x2 = 1.625 Take an integer of 1. The decimal part is 0.625.
0.625x2 = 1.25Take an integer of 1. The decimal part is 0.25.
0.25x2 = 0.5Take an integer of 0, and the decimal part is 0.5.
0.5x2 = 1.0Integer 1, decimal part is 0, end
Therefore, the binary value of 0.8125 is 0.1101.


An integer with three decimal places

You can directly combine the fractional part and the fractional part to get the sum of the integer and the decimal part.

For example, you can directly combine 22 and 0.8125 to get the value of 22.8125,

So the binary format of 22.8125 is: 10110.1101





Convert decimal to binary

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.