diff --git a/util.js b/util.js --- a/util.js +++ b/util.js @@ -1,4 +1,33 @@ -export function str2utf8(s){ +function bytes2int32(arr){ + return arr.reduce((acc,b,i)=>acc|b<<(i*8)); +} + +function bytes2int32s(arr){ + let res=[]; + for(let i=0;i>>=8; + } + return res; +} + +function int32s2bytes(arr){ + return arr.map(int322bytes).reduce((acc,bytes)=>acc.concat(bytes)); +} + +function bytes2hex(arr){ + return arr.map(x=>x.toString(16).padStart(2,"0")).join(""); +} + +function str2utf8(s){ let res=[]; let c=s.codePointAt(0); for(let i=0;c!==undefined;i++,c=s.codePointAt(i)){ @@ -23,7 +52,7 @@ export function str2utf8(s){ return res; } -console.log(str2utf8("$").map(x=>x.toString(16))); +/*console.log(str2utf8("$").map(x=>x.toString(16))); console.log(str2utf8("ยข").map(x=>x.toString(16))); console.log(str2utf8("โ‚ฌ").map(x=>x.toString(16))); -console.log(str2utf8("๐ˆ").map(x=>x.toString(16))); +console.log(str2utf8("๐ˆ").map(x=>x.toString(16)));*/