I'm new here. Using Javascript, I have successfully converted a Unicode character into a binary string (ie, into 1s and 0s). Now, how would I convert that string back into the original Unicode character (UTF-8 I think). I have found a few code examples--but unfortunately the conversions do not work in converting the binary string back into the original character.
Here's the binary string (which is a "thumbs up" emoji):
11110000100111111001000110001101
Thanks, and any code examples you could prove (in pure Javascript) would be most welcome. Thanks.
Basic Google-fu:
Putting above together (sorry for my poor JS skills):
function chunkSubstr(str, size) { const numChunks = Math.ceil(str.length / size) const chunks = new Array(numChunks) for (let i = 0, o = 0; i < numChunks; ++i, o += size) { chunks[i] = parseInt(str.substr(o, size),2) } return chunks } function uintToString(uintArray) { var encodedString = String.fromCharCode.apply(null, uintArray), decodedString = decodeURIComponent(escape(encodedString)); return decodedString; } console.log(uintToString(chunkSubstr("11110000100111111001000110001101", 8))); //
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.