Js values and strings can be converted to different bases
- 2020-03-30 02:16:21
- OfStack
When Javascript values and strings are converted, different bases can be manipulated.
The conversion example is as follows:
The conversion example is as follows:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> Convert between a numeric value and a string with base </title>
</head>
<body>
<script language="javascript">
//Number toString conversion :toString(), can be converted to different bases
function test1(){
var f = [1,2,3,4,5,6,7,8];
alert(f.reverse().join("")); //Array reverse function, connection function test
var b = parseInt(f.reverse().join("")).toString(2);
alert(b);
}
//Character to value conversion :parseInt(), converts data in different bases
function test2(){
var s = '10101010';
var b = parseInt(s,2);
alert(b);
}
test2();
</script>
</body>
</html>