In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "JavaScript how to achieve binary conversion", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "JavaScript how to achieve binary conversion" bar!
JavaScript to achieve binary conversion methods: 1, the use of parseInt () function, syntax "parseInt (value, to parse the value of the cardinality)"; 2, the use of toString () function, syntax "decimal number .toString (need to convert the base)".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
I. grammatical explanation
1. ParseInt ()
ParseInt: convert strings to integers
ParseInt (string, radix)
The string to be parsed by string.
Optional. Represents the cardinality of the number to parse. The value is between 2 and 36.
If the parameter is omitted or its value is 0, the number is parsed on the basis of 10.
If it starts with "0x" or "0X", it will have a base of 16.
If the parameter is less than 2 or greater than 36, parseInt () returns NaN.
2. ToString ()
The toString () method belongs to the Object object, which is overridden by many of JavaScript's built-in objects to better suit its own functional needs.
The type behavior description Array converts each element of Array into a string and concatenates them in turn, concatenating the two elements with an English comma as a delimiter. Boolean returns "true" if the Boolean value is true. Otherwise, "false" is returned. Date returns a text representation of the date. Error returns a string containing the relevant error information. Function returns a string in the following format, where functionname is the name of a function whose toString method is called: "function functionname () {[native code]}" Number returns a string representation of the numeric value. You can also return a string in the specified base, please refer to Number.toString (). String returns the value of the String object. Object (default) returns "[object ObjectName]", where ObjectName is the name of the object type. Binary conversion / / decimal conversion to other decimal var xonome110; alert (x); alert (x.toString (2)); alert (x.toString (8)); alert (x.toString (32)); alert (x.toString (16)); / / other decimal var xencoding 110bits; alert (parseInt (xMagne2)); / / 6 = > parsing 110alert in binary (parseInt (xmem8)) / / 72 = > parsing 110alert in octal (parseInt (xMagne16)); / / 272 = > parsing 110Band in hexadecimal / other to other / / converting parseInt to decimal and then using toString to target alert (String.fromCharCode (parseInt (141) alert (parseInt ('ff',16). ToString (2)) Thank you for your reading, the above is the content of "how to achieve binary conversion in JavaScript". After the study of this article, I believe you have a deeper understanding of how to achieve binary conversion in JavaScript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.