/** 把二级制数据转换成 hex 字符串 */ export function hexFromData(input: Uint8Array | ArrayBuffer, separator?: string) { if (input instanceof ArrayBuffer) { input = new Uint8Array(input) } else { input = new Uint8Array(input) } let hex: string[] = [] for (let i = 0; i < input.byteLength; i++) { let hexValue = (input as Uint8Array)[i].toString(16) if (hexValue.length < 2) { hexValue = "0" + hexValue } hex.push(hexValue) } return hex.join(separator ?? "") }