function hextobin(bin, hex, len)
{ //max wrote in 2018.4.26
console.log('hex:',hex);
var i;
var upper_str = hex.toUpperCase();
var dig;
var base;
//parseInt(j)
for (i=0; i<len; i++) {
if (upper_str.charCodeAt(i*2) >= 0x30 && upper_str.charCodeAt(i*2) <= 0x39)
base = 0x30;
else if (upper_str.charCodeAt(i*2) >= 0x41 && upper_str.charCodeAt(i*2) <= 0x5a)
base = 0x41-10;
else
base = 0;
if (base != 0){
bin[i] = (upper_str.charCodeAt(i*2)-base)<<4;
//console.log('bin1 :',bin.toString('hex'));
}
else
bin[i] = 0;
if (upper_str.charCodeAt(i*2+1) >= 0x30 && upper_str.charCodeAt(i*2+1) <= 0x39)
base = 0x30;
else if (upper_str.charCodeAt(i*2+1) >= 0x41 && upper_str.charCodeAt(i*2+1) <= 0x5a)
base = 0x41-10;
else
base = 0;
if (base != 0)
bin[i] |= upper_str.charCodeAt(i*2+1)-base;
//bin[i] = (((upper_str.charCodeAt(i*2)-65+10)<<4)|(upper_str.charCodeAt(i*2+1)-65+10));
}
console.log('bin.toString():',bin.toString('hex'));
//console.log('bin.toString():',bin);
//console.log("ori str", hex);
return bin;
}
{ //max wrote in 2018.4.26
console.log('hex:',hex);
var i;
var upper_str = hex.toUpperCase();
var dig;
var base;
//parseInt(j)
for (i=0; i<len; i++) {
if (upper_str.charCodeAt(i*2) >= 0x30 && upper_str.charCodeAt(i*2) <= 0x39)
base = 0x30;
else if (upper_str.charCodeAt(i*2) >= 0x41 && upper_str.charCodeAt(i*2) <= 0x5a)
base = 0x41-10;
else
base = 0;
if (base != 0){
bin[i] = (upper_str.charCodeAt(i*2)-base)<<4;
//console.log('bin1 :',bin.toString('hex'));
}
else
bin[i] = 0;
if (upper_str.charCodeAt(i*2+1) >= 0x30 && upper_str.charCodeAt(i*2+1) <= 0x39)
base = 0x30;
else if (upper_str.charCodeAt(i*2+1) >= 0x41 && upper_str.charCodeAt(i*2+1) <= 0x5a)
base = 0x41-10;
else
base = 0;
if (base != 0)
bin[i] |= upper_str.charCodeAt(i*2+1)-base;
//bin[i] = (((upper_str.charCodeAt(i*2)-65+10)<<4)|(upper_str.charCodeAt(i*2+1)-65+10));
}
console.log('bin.toString():',bin.toString('hex'));
//console.log('bin.toString():',bin);
//console.log("ori str", hex);
return bin;
}