From cb4fddc56b072c7cf526a9d26bf87bfb418fa1b6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Mon, 15 Aug 2016 17:50:23 +0200 Subject: [PATCH] new conversions: dec<->hex, dec<->bin --- .gitignore | 2 ++ dencode.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/.gitignore b/.gitignore index b25c15b..6d9446a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *~ +.idea/ +*.iml diff --git a/dencode.js b/dencode.js index f3897c8..a076423 100644 --- a/dencode.js +++ b/dencode.js @@ -99,6 +99,40 @@ } } }, + { + "id": "hextodec", + "name": "Decode hex as decimal", + "convert": function (input) { + try { + return { + "status": "OK", + "content": parseInt(input, 16).toString(10) + }; + } catch (exception) { + return { + "status": "ERROR", + "content": "Invalid number (integer) string." + }; + } + } + }, + { + "id": "bintodec", + "name": "Decode binary as decimal", + "convert": function (input) { + try { + return { + "status": "OK", + "content": parseInt(input, 2).toString(10) + }; + } catch (exception) { + return { + "status": "ERROR", + "content": "Invalid number (integer) string." + }; + } + } + }, { "id": "base64encode", "name": "Encode Base64", @@ -154,6 +188,40 @@ "content": quotedPrintable.encode(utf8.encode(input)) }; } + }, + { + "id": "dectohex", + "name": "Encode decimal as hex", + "convert": function (input) { + try { + return { + "status": "OK", + "content": parseInt(input).toString(16) + }; + } catch (exception) { + return { + "status": "ERROR", + "content": "Invalid number (integer) string." + }; + } + } + }, + { + "id": "dectobin", + "name": "Encode decimal as binary", + "convert": function (input) { + try { + return { + "status": "OK", + "content": parseInt(input).toString(2) + }; + } catch (exception) { + return { + "status": "ERROR", + "content": "Invalid number (integer) string." + }; + } + } } ];