JSのバイナリ変換は、バイナリ、オクタル、10進数、および六量体間の相互変換に分割されます。 Object.toString()を直接使用して実装できます。
次のコードを実行します
//小数をヘキサデシマル(10).toString(16)// => "A"に変換します。英語(0x16).toString(8)// => "26" //小数をバイナリに変換// =>(1111).toString(2)// => "100010111" //英語// =>(01111).toString(2)// => " binary // =>(0x16).toString(2)// => "10110"
バイナリを10進数から10進、小測数から小数、小数から小数まで処理する場合は、paresintメソッドを使用する必要があります。
次のコードを実行します
// 2桁から小数まで。 parseint(10,2)// => 2 // 2桁から小数まで。 parseint(100,2)// => 4 //ヘキサデシマルから10進数(12、16)// => 18 // 8桁から小数のparseint(12、8); // => 10
優先度変換
数字間で変換を実装する場合は、ParSeintメソッドを使用して最初に10進数に変換し、次にToString(パラメーター)を使用して異なる数字に変換できます。
ToStringおよびParseintメソッドを使用してバイナリ変換を実現するためのツール:
次のコードを実行します
< xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Unt titled document</title></head><body><script language="javascript">function test(){var num = document.getElementById( "in")。value; var type = document.getElementById( "title"); var tynum、to; for(var i = 0; i <type.length; i ++){if(type [i] .selected)tynum = parseint(type [i] value);} switch(tynum){case(1):to = parseint(num).tostring(2); break; case(2):to = parseint(num).tostring(8); b Reak; case(3):to = parseint(num).tostring(16); break; case(4):to = parseint(num、2); case(5):to = parseint(num、8); case(6):to = parseint(num、16); break; break; case(7):to = parseint(num); case(7); um、2).tostring(8); break; case(8):to = parseint(num、8).tostring(2); case(9):to = parseint(num、2).tostring(16); break; case(10):to = parseint(num、16).tostring(2); break(2); case(11); :to = parseint(num、8).tosttring(16); break; case(12):to = parseint(num、16).tostring(8);} if(isnan(to))to = "input Illegal Chargetle" document.getElementbyid( "out")。value= to;} Binary </option> <option値= "2">小数</option> <option value = "3"> decimal to hex </option> <option value = "4">バイナリから小数</option> <option> <option> <option> <option> <option> <option> <option> option> option> <option> <option value = "6" value = "8"> octal to binary </option> <option value = "9"> binary to hex </option> <option value = "10"> hex to binary </option> <option値> <"10"> hex to binary </option> <option値> <オプション値hex </option> <option value = "10"> hex to binary </option> <option value = "11"> octal to hexadecimal </option> <option value = "12"> hex to optal </option> </select> <br/> <入力タイプ= "テキスト" id = "in"/> <br> <input = ""/> < onclick = "test()"/> <font color = "#ff0000" style = "font-size:12px;">*注:違法文字がある場合、変換の有効な文字のみを切り捨てる</font> </body> </html>単純な暗号化と復号化
文字列をUnicodeに変換し、Unicodeを別のバイナリに変換してコード暗号化を実装します。
次のコードを実行します
<!doctype html> <html> <head> <meta charset = "utf-8"/> <title> </head> <body> <script> function en(code、h){//単純なjs暗号化と復号化<br> //コードは対応する文字列です。 array(); var i; code.split( "_"); "61_52307_52310_52310_" de( "61_52307_52310_52310_52310 _"、8)// => "1wahaha </scrip> </body> </html>ゼロワイド文字
width文字ゼロの幅ゼロ幅を使用して、すべての文字列をバイナリに変換し、ゼロ幅文字を使用してそれらを表現します。次に、生成された文字列の長さは0になり、これを再コンパイルすることで復元できます。
次のコードを実行します
<!doctype html> <html> <head> <meta charset = "utf-8"/> <title> </head> <body> <script> function en(var rep = {'00': '/u200b'、 '01': '/u200c'、 '/uf00d': '/uf00d': str.Replace(/[^/x00-/xff]/g、function(a){//ラテン-1以外のトランスコーディング文字エンコード。 a.charcodeat()。toString(2); a = a.length <8? {var rep = {"/u200b": "00"、 "/u200c": "01"、 "/u200d": "10"、 "/ufeff": "11"}; return string.fromCharcode(parseint(a.replace(/./ g、function(a){return rep [a]})、 2))上記は、編集者が紹介したJSのバイナリ変換と機能の完全な説明です。それがあなたに役立つことを願っています。もっと知りたい場合は、wulin.comのWebサイトに注意してください!