JS in-system conversion

Source: Internet
Author: User

The method of using JavaScript to convert into binary

Today in the Web site to use the conversion, so on-line search, found that you can directly use JavaScript's ToString () method and the parseint () method for the conversion between decimal and other binary, here to their usage of the collation.

ToString () Method: Converts decimal number to other binary number

parseint () Method: Convert other numbers to decimal

<script language= "javascript" type= "Text/javascript" >
var htmer=function (s) {document.write (' <br/> ' +s)}; Output results

Convert decimal numbers to other binary numbers
var x=123;
Htmer (x.tostring (2)); Convert to 2 binary
Htmer (x.tostring (8)); Convert to 8 binary
Htmer (X.tostring (16)); Convert to 16 binary

Convert other binary numbers to decimal numbers
var x= ' 10 ';
Htmer (parseint (x,2)); Converts 2 binary 10 to decimal
Htmer (parseint (x,8)); Converts 8 binary 10 to Decimal
Htmer (parseint (x,16)); Converts 16 binary 10 to decimal
</script>

Tip: If you want to convert between other binary numbers, you can convert them in decimal. For example, if you want to convert the 2 binary number to 8, you can convert the 2 binary number to decimal number, then convert the decimal number to the 8 binary number.

This article link address: http://www.htmer.com/article/618.htm

JS in-system conversion

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.