hex-my-bytes
Convert a list of bytes to a HEX string, and vice versa
Can be useful for debugging instances of TypedArray
.
Install
$ npm install hex-my-bytes
Or if you prefer using Yarn:
$ yarn add hex-my-bytes
Usage
// => '9b38ac3ec346' // => Uint8Array [ 155, 56, 172, 62, 195, 70 ]
API
toHex(bytes)
Convert an array of bytes to a lowercased hexadecimal string.
bytes
Type: number[]
A list of bytes.
Notes:
- Only the first 8 bits of the numbers are used while generating the string.
toBytes(hexString)
Convert a hexadecimal string to a list of bytes, creating a new instance of Uint8Array
.
hexString
Type: string
A hexadecimal string representing bytes.
Throws a TypeError
if the argument is not the correct type or if its length is an odd number.
Browser support
The latest version of Chrome, Firefox, and Safari.
Node.js support
hex-my-bytes requires Node.js 11 or later, but it indicates Node.js 8 in package.json
so you can use it with Node.js 8 by polyfilling the globals without having Yarn fail on install.