例如如何将图片
imagpath: "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg"
转换为二进制格式呢?
例如如何将图片
imagpath: "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg"
转换为二进制格式呢?
字符串转二进制:
var arr = [], str = "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg";
arr = arr.map.call(str, elem => elem.charCodeAt(0).toString(2));
console.log(arr)
// ["1101000", "1110100", "1110100", "1110000", "111010", "101111", "101111", "110001", "110010", "110100", "101110", "110001", "110001", "110100", "101110", "110001", "110111", "111001", "101110", "110111", "110111", "111010", "110110", "110111", "110100", "110100", "101111", "1111010", "1101000", "1100010", "1111000", "101111", "1101001", "1101101", "1100001", "1100111", "1100101", "101111", "110010", "110000", "110010", "110001", "110000", "111001", "110000", "110011", "101111", "1100110", "110101", "110001", "1100011", "110101", "1100101", "110111", "1100011", "1100011", "110111", "110100", "111001", "110100", "1100110", "110001", "1100011", "111001", "1100001", "1100010", "110110", "1100011", "110110", "110000", "110110", "110010", "111001", "110000", "1100101", "1100010", "1100010", "110110", "110001", "101110", "1101010", "1110000", "1100111"]
二进制转字符串
var str = arr.map(elem =>String.fromCharCode(parseInt(elem,2))).join('');
console.log(str)
// "http://124.114.179.77:6744/zhbx/image/20210903/f51c5e7cc7494f1c9ab6c606290ebb61.jpg"