Home > front end >  Javascript byte array to a string implementation process
Javascript byte array to a string implementation process

Time:09-16

Common method is below this online,
Var below one=arr [I]. ToString (2) is put into a binary string, byte value below the match match what does it mean, if my byte value is 1001, 0100
Here the v=one match (/^ 1 +? (?=0)/) of the result is what, you know the trouble to help see ah, thank you very much ~ ~ ~ ~

The function byteToString (arr) {
If (typeof arr==='string') {
Return arr.
}
Var STR=",
_arr=arr;
for(var i=0; i <_arr. Length; I++) {
Var one=_arr [I]. ToString (2),
V=one match (/^ 1 +? (?=0)/);
If (v & amp; & One. Length==8) {
Var bytesLength [0]=v. Length;
Var store=_arr [I]. ToString (2) slice (7 - bytesLength);
For (var st=1; St & lt; BytesLength; St++) {
Store +=_arr + I [st]. ToString (2) slice (2);
}
STR +=String. FromCharCode (parseInt (store, 2));
I +=bytesLength - 1;
} else {
STR +=String. FromCharCode (_arr [I]);
}
}
return str;
}

CodePudding user response:

Match (regexp), with regular to match a string, a match returns an array, otherwise it returns null

/^ 1 +? (?=0)/match at least a 1 at the beginning of greed, positive match suffix with 0 (at least 1 0)
  • Related