Guest User

Untitled

a guest
Jan 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. function Hex32BitToBinary(HexData){
  2. let result = "";
  3. //32bit hex to string
  4. HexData.match(/.{1,2}/g).forEach(str => {
  5. result += hex2bin(str)
  6. });
  7. return result;
  8. }
  9.  
  10. //Function to convert hex string to binary
  11. function hex2bin(hex) {
  12. let regEx = /^[0-9]*$/g;
  13. let binary = ("00000000" + (parseInt(hex, 16)).toString(2)).substr(-8);
  14. if (regEx.test(binary)) {
  15. return binary;
  16. } else {
  17. return null;
  18. }
  19. };
Add Comment
Please, Sign In to add comment