实例如下:

<script>

var symbols = " !\"#$%&'()*+,-./0123456789:;<=>";
var loAZ = "abcdefghijklmnopqrstuvwxyz";
symbols+= loAZ.toUpperCase();
symbols+= "[\\]^_`";
symbols+= loAZ;
symbols+= "{|}~";

//Hex to ASCII
function toAscii(str)
{
  valueStr = str.toLowerCase();
  var hex = "0123456789abcdef";
  var text = "";
  var i=0;

  for( i=0; i<valueStr.length; i=i+2 )
  {
    var char1 = valueStr.charAt(i);
    if ( char1 == ':' )
    {
      i++;
      char1 = valueStr.charAt(i);
    }
    var char2 = valueStr.charAt(i+1);
    var num1 = hex.indexOf(char1);
    var num2 = hex.indexOf(char2);
    var value = num1 << 4;
    value = value | num2;

    var valueInt = parseInt(value);
    var symbolIndex = valueInt - 32;
    var ch = '"0123456789abcdef";
  var text = "";
  for( i=0; i<valueStr.length; i++ )
  {
    var oneChar = valueStr.charAt(i);
    var asciiValue = symbols.indexOf(oneChar) + 32;
    var index1 = asciiValue % 16;
    var index2 = (asciiValue - index1)/16;
    if ( text != "" ) text += ":";
    text += hexChars.charAt(index2);
    text += hexChars.charAt(index1);
  }
  return text;
}


</script>

以上就是小编为大家带来的javascript ASCII和Hex互转的实现方法全部内容了,希望大家多多支持~

标签:
hex转ascii

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“javascript ASCII和Hex互转的实现方法”

暂无“javascript ASCII和Hex互转的实现方法”评论...