betway必威-betway必威官方网站
做最好的网站

JavaScript转换二进制编码为ASCII码的方法_javascrip

本文实例讲述了JavaScript转换二进制编码为ASCII码的方法。分享给大家供大家参考。具体如下:

var input_id = "bin_text";var answer_id = "answer";function convertToASCII() { var bin_text = document.getElementById; var answer = document.getElementById; if  { alert("Error: No element with id "" answer_id ""."); return; } if  var text = bin_text.value; else { error("No element with id "" input_id ""."); return; } var divisible = text.length % 8; var nonBinary = /[^0|1]/.test; if (text.length > 0 && divisible == 0 && !nonBinary) { var regex = /[0|1]{8}/g; var str = text.match; var code = 0; var placeVal, exp, digit; var ascii = ''; while  { code = 0; for (var i=0; i<str[0].length; i  ) { placeVal = 7-i; exp = Math.pow; digit = str[0].charAt; code  = exp*digit; } str.shift(); ascii  = String.fromCharCode; } answer.innerHTML = "<p class="binary">"   ascii   "</p>"; } else { error; return; } function error { answer.innerHTML = "<span class="error">Error: "   errText   "</span>"; }}.block { width: 45%; border: 1px solid #000000; padding: 10px;}.binary { background-color: #C6FFC7; padding: 3px;}.error { background-color: #FFC6C6; padding: 3px;}  

希望本文所述对大家的javascript程序设计有所帮助。

本文由betway必威发布于网络技术,转载请注明出处:JavaScript转换二进制编码为ASCII码的方法_javascrip

TAG标签: betway必威
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。