Skip to content

Instantly share code, notes, and snippets.

@alemohamad
Created January 9, 2014 15:33
Show Gist options
  • Save alemohamad/8335967 to your computer and use it in GitHub Desktop.
Save alemohamad/8335967 to your computer and use it in GitHub Desktop.
Convert integer to binary or hexadecimal, and the other way.
function dec2bin(number) {
return number.toString(2);
}
function bin2dec(number) {
return parseInt(number, 2);
}
function dec2hex(number) {
return number.toString(16);
}
function hex2dec(number) {
return parseInt(number,16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment