关于用JS解码Base64或二进制流8位制的编码方法之一


const blob = window.atob(value) // Base64 string converted to a char array
const fLen = blob.length / Float32Array.BYTES_PER_ELEMENT // How many floats can be made, but be even
const dView = new DataView(
new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT)
) // ArrayBuffer/DataView to convert 4 bytes into 1 float.
let fAry = new Float32Array(fLen) // Final Output at the correct size
let p = 0 // Position
 
for (let j = 0; j < fLen; j++) {
p = j * 4
dView.setUint8(0, blob.charCodeAt(p))
dView.setUint8(1, blob.charCodeAt(p + 1))
dView.setUint8(2, blob.charCodeAt(p + 2))
dView.setUint8(3, blob.charCodeAt(p + 3))
fAry[j] = dView.getFloat32(0, true)
}
console.log(fAry) 

value = "AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA"

value = 'AAAAAA==' 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM