//十进制转其他进制
var x=110;
alert(x);
alert(x.toString(2));
alert(x.toString(8));
alert(x.toString(32));
alert(x.toString(16));
//其他转十进制
var x=\'110\';
alert(parseInt(x,2)); //6 =>以2进制解析110
alert(parseInt(x,8)); //72 =>以8进制解析110
alert(parseInt(x,16)); //272 =>以16进制解析110
//其他转其他
//先用parseInt转成十进制再用toString转到目标进制
alert(String.fromCharCode(parseInt(141,8)))
alert(parseInt(\'ff\',16).toString(2));
Write a function that takes an (unsigned) integer as input, and returns the number of bits that are equal to one in the binary representation of that number.
Example: The binary representation of 1234
is 10011010010
, so the function should return 5
in this case
本文作者starof,因知识本身在变化,作者也在不断学习成长,文章内容也不定时更新,为避免误导读者,方便追根溯源,请诸位转载注明出处:http://www.cnblogs.com/starof/p/6693318.html有问题欢迎与我讨论,共同进步。