Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 解码二进制字符串如何反应_React Native - Fatal编程技术网

React native 解码二进制字符串如何反应

React native 解码二进制字符串如何反应,react-native,React Native,如何将二进制中的字符串再次转换为react native中的字符串 例:01010向您好 我有把字符串转换成二进制的代码 例如:text.split.mapl=>l.charCodeAt0.toString2.join“” 只需将二进制字符串转换回整数,并使用fromCharCode将这些值映射到字符 要将二进制字符串转换为sting,可以使用parseInt和string.fromCharCode parseInt将字符串转换为数字。第一个参数是字符串值,第二个参数是表示字符串的基值 设num

如何将二进制中的字符串再次转换为react native中的字符串

例:01010向您好

我有把字符串转换成二进制的代码

例如:text.split.mapl=>l.charCodeAt0.toString2.join“”

只需将二进制字符串转换回整数,并使用fromCharCode将这些值映射到字符


要将二进制字符串转换为sting,可以使用parseInt和string.fromCharCode

parseInt将字符串转换为数字。第一个参数是字符串值,第二个参数是表示字符串的基值

设num=parseIntbinaryStr,2; String.fromCharCode将字符代码转换为匹配字符串

设str=String.fromCharCode65; 用示例完成代码:

常量文本='Hello' 让binaryStr=text.split.mapl=>l.charCodeAt0.toString2.join''; log'Binary string:',binaryStr; //将二进制文件转换为字符串 让strVal=binaryStr.split'.mapl=>String.fromCharCodeparseIntl,2.join; log'String:',strVal; 上述代码的输出:

二进制字符串:1001000 1100101 1101100 1101100 1101111

字符串:你好

let txt="Hello".split('').map(l => l.charCodeAt(0).toString(2)).join(' ')
       
let s = txt.split(" ").map(w=> String.fromCharCode(parseInt(w,2)))

console.log(s.join(""))