Created
October 30, 2018 12:37
-
-
Save Janaka-Steph/46f010718fe527d103fe7e0bdb9dcd0a to your computer and use it in GitHub Desktop.
Convert From/To Binary/Decimal/Hexadecimal in JavaScript + calculate byte length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convert = { | |
bin2dec : s => parseInt(s, 2).toString(10), | |
bin2hex : s => parseInt(s, 2).toString(16), | |
dec2bin : s => parseInt(s, 10).toString(2), | |
dec2hex : s => parseInt(s, 10).toString(16), | |
hex2bin : s => parseInt(s, 16).toString(2), | |
hex2dec : s => parseInt(s, 16).toString(10), | |
lenBytesDec: bin => (bin.length/8).toString(10), | |
lenBytesHex: bin => (bin.length/8).toString(16), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment