function bin2hex(s){
s=encodeURI(s);//只会有0-127的ascii不转化
var m=s.match(/%[\dA-F]{2}/g),a=s.split(/%[\dA-F]{2}/),i,j,n,t
m.push(“”)
for(i in a){
if(a[i] === “”){a[i]=m[i];continue}
n=””
for(j in a[i]){
t=a[i][j].charCodeAt().toString(16).toUpperCase()
if(t.length === 1) t=”0″+t
n+=”%”+t
}
a[i]=n+m[i]
}
return a.join(“”).split(“%”).join(“”)
}
// 模拟hex2bin
function hex2bin(s){
var len=s.length
if(len%2) return false
var i,a=[]
for(i=0;i<len;i+=2) a[i/2]=”%”+s.substr(i,2)
return decodeURIComponent(a.join(“”))
}