Skip to content

Instantly share code, notes, and snippets.

@noncom
Created February 28, 2018 09:38
Show Gist options
  • Save noncom/c6a29387bc6eb76d750a0d9990d710f1 to your computer and use it in GitHub Desktop.
Save noncom/c6a29387bc6eb76d750a0d9990d710f1 to your computer and use it in GitHub Desktop.
<!--//--><![CDATA[// ><!--
function codeTel2Txt( instr ) {
var intval = parseInt(instr,10);
var codeP1 = parseInt(((intval/10000)|0)%100,16);
var codeP2 = parseInt((intval%10000),16);
var codeText = ("000" + codeP1).slice(-3) + ',' + ("00000" + codeP2).slice(-5);
return codeText;
}
function codeTel2Hex( instr ) {
var codeHex = ("000000"+instr).slice(-6);
return codeHex.toUpperCase();
}
function codeHex2Tel( instr ) {
var codeHex = instr.toUpperCase();
if (codeHex.match(/[A-Z]/i)) {
// alphabet letters found
return "Не существует";
}
return codeHex;
}
function codeTxt2Hex( instr ) {
var l = instr.length;
var p = instr.indexOf(",");
var codeP1 = instr.substring(0, p);
var codeP2 = instr.substring(p+1);
var codeP1I = parseInt(codeP1,10);
var codeP2I = parseInt(codeP2,10);
var codeP1H = codeP1I.toString(16);
var codeP2H = codeP2I.toString(16);
// var p2 = new Array( 5 - codeP2H.length ).join( "0" );
var codeHex = codeP1H + ("0000"+codeP2H).slice(-4);
codeHex = ("000000"+codeHex).slice(-6);
// codeHex = codeHex.substring(4,6) + codeHex.substring(2,4) + codeHex.substring(0,2);
return codeHex.toUpperCase();
}
function codeHex2Txt( instr ) {
// var codeHex = instr.substring(4,6) + instr.substring(2,4) + instr.substring(0,2);
var codeHex = instr.toUpperCase();
var l = codeHex.length;
var codeP1 = codeHex.substring(0,l-4);
var codeP2 = codeHex.substring(l-4);
var codeP1I = parseInt(codeP1,16);
var codeP2I = parseInt(codeP2,16);
var codeText = ("000" + codeP1I).slice(-3) + ',' + ("00000" + codeP2I).slice(-5);
return codeText;
}
function codeHex2Dec( instr ) {
// codeHex = instr.substring(4,6) + instr.substring(2,4) + instr.substring(0,2);
var codeHex = instr.toUpperCase();
var codeInt = parseInt(codeHex,16);
var codeDec = ("0000000000" + codeInt).slice(-10);
return codeDec;
}
function codeDec2Hex( instr ) {
var codeInt = parseInt(instr,10);
var codeHex = codeInt.toString(16);
var codeHex = ("000000" + codeHex).slice(-6);
// codeHex = codeHex.substring(4,6) + codeHex.substring(2,4) + codeHex.substring(0,2);
return codeHex.toUpperCase();
}
function codePan2Hex( instr ) {
// Заменить 0 на a
var codeHex = instr.replace(/0/g,"A");
var l = codeHex.length;
// 6 символов max - последних!
if (l>6) { codeHex = codeHex.substring(l-6); }
// Дополнить до 6 нулями спереди
if (l<6) { codeHex = ("000000" + codeHex).slice(-6); }
// Реверс 6 символов попарно
// codeHex = codeHex.substring(4,6) + codeHex.substring(2,4) + codeHex.substring(0,2);
return codeHex.toUpperCase();
}
function codeHex2Pan( instr ) {
// Реверс 6 символов попарно
// codeHex = instr.substring(4,6) + instr.substring(2,4) + instr.substring(0,2);
var codeHex = instr.toUpperCase();
var codeInt = parseInt(codeHex,16);
codeHex = codeInt.toString(16).toUpperCase();
// Если есть 0 то не существует
if (codeHex.match(/[0]/i)) {
// alphabet letters found
return "Не существует";
}
// Заменить A на 0
var codePan = codeHex.replace(/A/g,"0");
if (codePan.match(/[A-Z]/i)) {
// alphabet letters found
return "Не существует";
}
// codePan = parseInt(codePan,10);
return codePan; //.toString();
}
function convertIt() {
var codeDec = document.getElementById("code_dec").value;
codeDec = codeDec.replace(/\s+/g, '');
document.getElementById("code_dec").value = codeDec;
var codeHex = codeDec2Hex(codeDec);
document.getElementById("code_hex").value = codeHex;
document.getElementById("code_txt").value = codeHex2Txt(codeHex);
document.getElementById("code_pan").value = codeHex2Pan(codeHex);
}
function convertIt1() {
var codeHex = document.getElementById("code_hex1").value;
codeHex = codeHex.replace(/\s+/g, '');
document.getElementById("code_hex1").value = codeHex;
document.getElementById("code_dec1").value = codeHex2Dec(codeHex);
document.getElementById("code_txt1").value = codeHex2Txt(codeHex);
document.getElementById("code_pan1").value = codeHex2Pan(codeHex);
}
function convertIt2() {
var codeTxt = document.getElementById("code_txt2").value;
codeTxt = codeTxt.replace(/\s+/g, '');
document.getElementById("code_txt2").value = codeTxt;
var codeHex = codeTxt2Hex(codeTxt);
document.getElementById("code_dec2").value = codeHex2Dec(codeHex);
document.getElementById("code_hex2").value = codeHex;
document.getElementById("code_pan2").value = codeHex2Pan(codeHex);
}
function convertIt3() {
var codePan = document.getElementById("code_pan3").value;
// var codeTxt = document.getElementById("code_txt3").value;
var codeHex = codePan2Hex( codePan );
document.getElementById("code_hex3").value = codeHex;
var codeTxt = codeHex2Txt( codeHex );
document.getElementById("code_txt3").value = codeTxt;
var codeDec = codeHex2Dec(codeHex);
document.getElementById("code_dec3").value = codeDec;
}
function convertIt4() {
var codeTel = document.getElementById("code_tel4").value;
// var codeTxt = document.getElementById("code_txt3").value;
var codeHex = codeTel2Hex( codeTel );
document.getElementById("code_hex4").value = codeHex;
var codeTxt = codeHex2Txt( codeHex );
document.getElementById("code_txt4").value = codeTxt;
var codeDec = codeHex2Dec(codeHex);
document.getElementById("code_dec4").value = codeDec;
}
//--><!]]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment