function dec2hex(s){return(s+0).toString(16).toUpperCase();}

function charToCode(s){
  var o="",h=0,n=0;
  for(var i=0;i<s.length;i++){
    var b=s.charCodeAt(i);
    if(b<0||b>0xFFFF){o+='!erreur '+dec2hex(b)+'!';}
    if(h!=0){
      if(0xDC00<=b&&b<=0xDFFF){o+=dec2hex(0x10000+((haut-0xD800)<<10)+(b-0xDC00))+' ';h=0;continue;}
      else{o+='!error '+dec2hex(haut)+'!';h=0;}
    }
    if(0xD800<=b&&b<=0xDBFF){h=b;}else{o+=dec2hex(b)+' ';}
  }
  return(o.replace(/ $/,''));
}

function convert(s){
  var o="";s=charToCode(s).replace(/^\s+/,'');if(s.length==0){return "";}s=s.replace(/\s+/g,' ');var l=s.split(' ');
  for(var i=0;i<l.length;i++){var n=parseInt(l[i],16);o+=('&#'+n+';');}
  return(o);
}
