JS basic _ other base numbers

tags: JavaScript

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			
			var a = 123;
			
			/*
			 * In js, if you need to represent a hexadecimal number, you need to start with 0x
			  * If you need to represent an octal number, you need to start with 0
			  * If you want to represent a binary number, you need to start with 0b
			  * But not all browsers support
			 * 	
			 */
			
			 //Hexadecimal
			a = 0x10;
			a = 0xff;
			a = 0xCafe;
			
			 //Octal number
			a = 070;
			
			 //Binary number
			//a = 0b10;
			
			 //For the string "070", some browsers will parse it as octal, and some will parse it as decimal
			a = "070";
			
			 //You can pass a second parameter in parseInt() to specify the base of the number
			a = parseInt(a,10);
			
			alert(typeof a);//number
			alert(a);       //70
			
		</script>
	</head>
	<body>
	</body>
</html>

 

Intelligent Recommendation

Js numbers and methods (emphasis on basic knowledge)

JavaScript values ​​are always 64-bit floating point numbers Unlike many other programming languages, JavaScript does not define different types of numbers, such as integer, short, long, floating poin...

js- base - scopes, with chain domain, the basic concept of closure

Scope : Is a run-time execution environment functions. Basic Concepts: each object is a JavaScript function, object, we can access some of the properties, we can not access some of these properties ar...

Binary to other base conversion

Method: the integer part of the base number is continuously divided to take the remainder (from bottom to top), and the decimal part of the base number is continuously multiplied and rounded (from top...

Binary and other base conversion

Example: Known: The basic storage unit of a computer is byte, and a byte has 8 bits. The maximum value of 8-digit binary system = (11111111) 2 Write a program to calculate and display the maximum valu...

More Recommendation

JavaScript's other base values

JS supports converting decimal values ​​into octal and hexadecimal values ​​directly The hexadecimal direct quantity is prefixed with "0X" or "0x", followed by the hexadecimal valu...

JS: Force data conversion, convert other data to Number, other hexadecimal numbers

In js, hexadecimal numbers start with 0x, octal numbers start with 0 Binary numbers need to start with 0b, but not all browsers support...

Base for the conversion of large numbers

Input Output Sample Input Sample Output Ideas: BigInteger solved by the java class. Code:...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top