The usual development work does not involve the conversion between binary to decimal, decimal and so on. Recently, the OCX plug-in has written the relevant information to the CPU card, so it is necessary to convert the data and record the memo.Copy the code
1. Convert binary to hexadecimal
Function twoToSixten(num) {var value=parseInt(num,2).toString(16); return value; }Copy the code
2, decimal to binary
Function tenToTwo(num) {var value=parseInt(num).tostring (2); return value; }Copy the code
3. Convert decimal to hexadecimal
Function toHex(num){var rs = ""; var temp; While (num/16 > 0){temp = num%16; rs = (temp+"").replace("10","a").replace("11","b").replace("12","c").replace("13","d").replace("14","e").replace("15","f") + Rs. Num = parseInt (num / 16); } return rs; }Copy the code