Hex string to byte and other way round conversion functions.
function byteToHexString(uint8arr) { | |
if (!uint8arr) { | |
return ''; | |
} | |
var hexStr = ''; | |
for (var i = 0; i < uint8arr.length; i++) { | |
var hex = (uint8arr[i] & 0xff).toString(16); | |
hex = (hex.length === 1) ? '0' + hex : hex; | |
hexStr += hex; | |
} | |
return hexStr.toUpperCase(); | |
} | |
function hexStringToByte(str) { | |
if (!str) { | |
return new Uint8Array(); | |
} | |
var a = []; | |
for (var i = 0, len = str.length; i < len; i+=2) { | |
a.push(parseInt(str.substr(i,2),16)); | |
} | |
return new Uint8Array(a); | |
} |
This comment has been minimized.
This comment has been minimized.
@cprcrack The intent of |
This comment has been minimized.
This comment has been minimized.
Thx))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Assuming the input is always a Uint8Array, what is the use of
& 0xff
in line 8?