UNPKG

@fruitsjs/util

Version:

Useful utilities and tools for building Fruits Eco-Blockchain applications

17 lines (16 loc) 693 B
/** * Converts byte array to hexadecimal string * Inverse operation of [[convertHexStringToByteArray]] * @param bytes The (unsigned) byte array to be converted * @param uppercase If _true_, converts hex string with uppercase characters (Default: false) * @return {string} A hex string representing the byte array input * @module util */ export const convertByteArrayToHexString = (bytes: Uint8Array, uppercase = false): string => { const hex = []; for (let i = 0; i < bytes.length; i++) { hex.push((bytes[i] >>> 4).toString(16)); hex.push((bytes[i] & 0xF).toString(16)); } return uppercase ? hex.join('').toUpperCase() : hex.join(''); };