关于用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=='
标签:setUint8,编码方法,dView,const,Base64,JS,blob,charCodeAt,new 来源: https://www.cnblogs.com/xiaozhu007/p/11383898.html