Skip to content

Instantly share code, notes, and snippets.

@johnfoderaro
Last active October 14, 2022 09:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnfoderaro/f960aafdaed087a1163c to your computer and use it in GitHub Desktop.
Save johnfoderaro/f960aafdaed087a1163c to your computer and use it in GitHub Desktop.
A simple function to convert a variable value to binary.
function binaryConvert() {
var num = x;
if (num != Math.floor(num)) {
console.log("Please enter a number");
} else if (num < 0) {
console.log("Please enter a positive number");
} else {
var binary = parseInt(num, 10);
console.log(binary.toString(2));
}
}
binaryConvert();
@Bryan-Cee
Copy link

Pretty neat 👍

@lucas-moont
Copy link

Great job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment