Created
January 18, 2019 12:06
-
-
Save ICeZer0/f72b8cab4737c021e33414bd1fc39cc0 to your computer and use it in GitHub Desktop.
Converts 4 byte Hex to 32 bit binary string
This file contains 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
function Hex32BitToBinary(HexData){ | |
let result = ""; | |
//32bit hex to string | |
HexData.match(/.{1,2}/g).forEach(str => { | |
result += hex2bin(str) | |
}); | |
return result; | |
} | |
//Function to convert hex string to binary | |
function hex2bin(hex) { | |
let regEx = /^[0-9]*$/g; | |
let binary = ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8); | |
if (regEx.test(binary)) { | |
return binary; | |
} else { | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment