Skip to content

Instantly share code, notes, and snippets.

@uqmessias
Last active February 1, 2020 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uqmessias/66f3de0da2f60419b39f26ca243f3e2a to your computer and use it in GitHub Desktop.
Save uqmessias/66f3de0da2f60419b39f26ca243f3e2a to your computer and use it in GitHub Desktop.
Converts an input parameter from Decimal to Hexadecimal
/**
* If you want to use it, you first need to install
* Deno at https://deno.land and run:
* deno https://gist.github.com/uqmessias/66f3de0da2f60419b39f26ca243f3e2a/raw 222
*/
function throwError(wrongArgument = null) {
const argumentError =
wrongArgument === null
? ""
: `"${wrongArgument}" is not a valid argument!\n\n`;
throw new Error(
`${argumentError}You must provide at least one decimal number as an argument.
# If you wish to convert only one decimal number, you can provide it as the only argument.
deno https://gist.github.com/uqmessias/66f3de0da2f60419b39f26ca243f3e2a/raw 222
# And you still can provide serveral decimal numbers as arguments in order to convert them.
deno https://gist.github.com/uqmessias/66f3de0da2f60419b39f26ca243f3e2a/raw 234 199 02`
);
}
if (!Deno.args.length) {
throwError();
} else {
Deno.args.forEach(function(arg) {
const dec = parseInt(arg, 10);
if (isNaN(dec)) {
throwError(arg);
return;
}
console.log(`"${dec}" converted to "${dec.toString(16).toUpperCase()}"`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment