Last active
August 25, 2021 23:50
-
-
Save LRENZ/a5339da224293e1f30a0867d94ead8bd to your computer and use it in GitHub Desktop.
convert_28_openid_to_38_digital number.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = 'od3P-t1o5NOTl4ketBHZ1kZ0DBio'; | |
function convert(str) { | |
if (str.length == 28) { | |
var binary = [] | |
var num = [] | |
var binary_str | |
for (var i = 0; i < str.length; i++) { | |
var binStr = str.charCodeAt(i).toString(2).padStart(8, "0"); // 补全为8位数字 ex:01110110 | |
binary.push(binStr); | |
} | |
binary_str = binary.join("")+"0000" //补全为 228 = 6x38 | |
binary_str = binary_str.match(/.{6}/g) // 上面字符每 6个分成一组,总共38组 | |
for (var j = 0; j < binary_str.length; j++) { | |
var dec = parseInt(binary_str[j], 2) //每一组转成10进制 | |
//console.log(dec) | |
num.push(dec % 10) //取个位数 | |
} | |
return num.join("") //补全最后一位 | |
} | |
} | |
var t = convert(str) | |
t | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment