JS hexadecimal conversion and its functions; JS hexadecimal conversion

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

JS hexadecimal conversion and its functions; JS hexadecimal conversion

Js hexadecimal conversion is divided into two hexadecimal, octal, 10-hexadecimal, and hexadecimal conversion. We can directly use the object. toString () to achieve this:

Run the following code:

// Convert the hexadecimal value to the hexadecimal value (10 ). toString (16) // => "a" // convert the hexadecimal value to the hexadecimal value (012 ). toString (16) // => "a" // convert the hexadecimal value to the hexadecimal value (0x16 ). toString (10) // => "22" // convert the hexadecimal value to the hexadecimal value (0x16 ). toString (8) // => "26" // convert the hexadecimal value to a binary value. // => (1111 ). toString (2) // => "10001010111" // convert the hexadecimal value to a binary value. // => (01111 ). toString (2) // => "1001001001" // convert hexadecimal format to binary format // => (0x16 ). toString (2) // => 10110"

If you want to process binary to decimal, hexadecimal to decimal, and hexadecimal to decimal, you need to use the paresInt method:

Run the following code:

// 2 to 10; parseInt () // => 2/2 to 10; parseInt) // => 4 // hexadecimal to 10 hexadecimal parseInt (12, 16) // => 18 // octal to 10 hexadecimal parseInt (12, 8 ); // => 10

Hexadecimal conversion

If you want to convert between the current hexadecimal values, you can use the parseInt method to convert them to the 10th hexadecimal value first, and then use the toString (parameter) to convert them into different hexadecimal values;

The toString and parseInt methods can be used to implement a hexadecimal conversion tool:

Run the following code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

  Simple encryption and decryption

Convert a string to unicode, and convert unicode to a different hexadecimal format to implement code encryption:

Run the following code:

<! DOCTYPE html> 

  Zero-width characters

With zero-width characters and zero-width characters, we convert all strings into binary values, and then use zero-width characters for representation. Then, the length of the generated string is 0, which can be restored by decompiling,

Run the following code:

<! DOCTYPE html> 

The above is a full description of the hexadecimal conversion and function in Javascript. I hope it will be helpful to you. If you want to learn more, please stay tuned to the help House website!

Related Article

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.