diff options
author | friendica <info@friendica.com> | 2014-06-05 17:42:48 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-06-05 17:42:48 -0700 |
commit | c4fc9a9cf69fd87e4ab9136e6b4eaa9b1a9266b2 (patch) | |
tree | 5caea58e2c0a11a5592876f7761b02340a12cbbd | |
parent | 359814eee7a1a5de0af5a096aed8adf974608099 (diff) | |
download | volse-hubzilla-c4fc9a9cf69fd87e4ab9136e6b4eaa9b1a9266b2.tar.gz volse-hubzilla-c4fc9a9cf69fd87e4ab9136e6b4eaa9b1a9266b2.tar.bz2 volse-hubzilla-c4fc9a9cf69fd87e4ab9136e6b4eaa9b1a9266b2.zip |
move hexit to addons where it belongs
-rw-r--r-- | app/hex.apd | 3 | ||||
-rw-r--r-- | app/hex.png | bin | 12239 -> 0 bytes | |||
-rw-r--r-- | mod/hexit.php | 181 | ||||
-rw-r--r-- | version.inc | 2 |
4 files changed, 1 insertions, 185 deletions
diff --git a/app/hex.apd b/app/hex.apd deleted file mode 100644 index 0537a1b8f..000000000 --- a/app/hex.apd +++ /dev/null @@ -1,3 +0,0 @@ -url: $baseurl/hexit -name: Hexit -photo: $baseurl/app/hex.png diff --git a/app/hex.png b/app/hex.png Binary files differdeleted file mode 100644 index ce4da8d46..000000000 --- a/app/hex.png +++ /dev/null diff --git a/mod/hexit.php b/mod/hexit.php deleted file mode 100644 index 2c65fd9d4..000000000 --- a/mod/hexit.php +++ /dev/null @@ -1,181 +0,0 @@ -<?php - - - - - - - - - - - - - -function hexit_content(&$a) { - - -$o .= <<< EOT - -<script type="text/javascript"> -/** - * A function for converting hex <-> dec w/o loss of precision. - * - * The problem is that parseInt("0x12345...") isn't precise enough to convert - * 64-bit integers correctly. - * - * Internally, this uses arrays to encode decimal digits starting with the least - * significant: - * 8 = [8] - * 16 = [6, 1] - * 1024 = [4, 2, 0, 1] - */ - -// Adds two arrays for the given base (10 or 16), returning the result. -// This turns out to be the only "primitive" operation we need. -function add(x, y, base) { - var z = []; - var n = Math.max(x.length, y.length); - var carry = 0; - var i = 0; - while (i < n || carry) { - var xi = i < x.length ? x[i] : 0; - var yi = i < y.length ? y[i] : 0; - var zi = carry + xi + yi; - z.push(zi % base); - carry = Math.floor(zi / base); - i++; - } - return z; -} - -// Returns a*x, where x is an array of decimal digits and a is an ordinary -// JavaScript number. base is the number base of the array x. -function multiplyByNumber(num, x, base) { - if (num < 0) return null; - if (num == 0) return []; - - var result = []; - var power = x; - while (true) { - if (num & 1) { - result = add(result, power, base); - } - num = num >> 1; - if (num === 0) break; - power = add(power, power, base); - } - - return result; -} - -function parseToDigitsArray(str, base) { - var digits = str.split(''); - var ary = []; - for (var i = digits.length - 1; i >= 0; i--) { - var n = parseInt(digits[i], base); - if (isNaN(n)) return null; - ary.push(n); - } - return ary; -} - -function convertBase(str, fromBase, toBase) { - var digits = parseToDigitsArray(str, fromBase); - if (digits === null) return null; - - var outArray = []; - var power = [1]; - for (var i = 0; i < digits.length; i++) { - // invariant: at this point, fromBase^i = power - if (digits[i]) { - outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase); - } - power = multiplyByNumber(fromBase, power, toBase); - } - - var out = ''; - for (var i = outArray.length - 1; i >= 0; i--) { - out += outArray[i].toString(toBase); - } - return out; -} - -function decToHex(decStr) { - var hex = convertBase(decStr, 10, 16); - return hex ? '0x' + hex : null; -} - -function hexToDec(hexStr) { - if (hexStr.substring(0, 2) === '0x') hexStr = hexStr.substring(2); - hexStr = hexStr.toLowerCase(); - return convertBase(hexStr, 16, 10); -} - - - - function str_or_null(x) { - return x === null ? 'null' : x; - } - - // "1.234e+5" -> "12340" - function expandExponential(x) { - var pos = x.indexOf("e"); - if (pos === -1) pos = x.indexOf("E"); - if (pos === -1) return x; - - var base = x.substring(0, pos); - var pow = parseInt(x.substring(pos + 1), 10); - if (pow < 0) return x; // not supported. - - var dotPos = base.indexOf('.'); - if (dotPos === -1) dotPos = base.length; - - var ret = base.replace('.', ''); - while (ret.length < dotPos + pow) ret += '0'; - return ret; - } - - function boldDifference(correct, actual) { - for (var i = 0, j = 0; i < correct.length && j < actual.length; i++, j++) { - if (correct[i] !== actual[j]) { - break; - } - } - if (j < actual.length) { - return actual.substring(0, j) + '<b>' + actual.substring(j) + '</b>'; - } else { - return actual; - } - } - - function convert() { - var input = document.getElementById("in").value; - if (input) { - var aHex = str_or_null(decToHex(input)); - var aDec = str_or_null(hexToDec(input)); - var bHex = '0x' + (parseInt(input, 10)).toString(16); - var bDec = "" + expandExponential("" +parseInt(input, 16)); - - var html = '<p></p><p>To Decimal(' + input + ') = ' + aDec + '</p>'; - html += '<p>To Hex(' + input + ') = ' + aHex + '</p>'; - document.getElementById('result').innerHTML = html; - } - } - convert(); - - -</script> - - <h2>Hexit</h2> - - <p>Type in a hex or decimal string:</p> - <input type="text" size=40 id="in" onkeyup="convert()" value="" /> - <p id="result"></p> - - - -EOT; - -return $o; -} diff --git a/version.inc b/version.inc index 1bedfc22b..16fe33e87 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-06-04.696 +2014-06-05.697 |