Binary to decimal and decimal to binary Algorithms

Source: Internet
Author: User
Tags binary to decimal decimal to binary

Convert decimal to binary: 
The result is 1 after 2 rounds.
Write the remainder and the last 1 in descending order as the result.
For example, 302
302/2 = 151 + 0
151/2 = 75 + 1
75/2 = 37 + 1
37/2 = 18 + 1
18/2 = 9 + 0
9/2 = 4 + 1
4/2 = 2 + 0
2/2 = 1 + 0
The binary value is 100101110.

Convert binary to decimal 
Start from the last digit and column it as 0th, 1, 2...
The number (0 or 1) of the nth digit multiplied by the Npower of 2
The result is the answer.
Example: 01101011. Convert to decimal:
0th bits: 1 multiplied by 2 to the power of 0 = 1
1 to the power of 2 = 2
0 multiplied by the 2's power = 0
1 multiplied by the power of 2 = 8
0 multiplied by the power of 2 = 0
1 multiplied by the power of 2 = 32
1 multiplied by the power of 2 = 64
0 multiplied by the power of 2 = 0
Then: 1 + 2 + 0
+ 8 + 0 + 32 + 64 + 0 = 107.
Binary 01101011 = decimal 107.

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.