Skip to content

Commit

Permalink
utils.bytesToHex: small change
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 21, 2024
1 parent 7d19052 commit 9574a28
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export function bytesToHex(bytes: Uint8Array): string {
}

// We use optimized technique to convert hex string to byte array
const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const;
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;
function asciiToBase16(ch: number): number | undefined {
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48
if (ch >= asciis._A && ch <= asciis._F) return ch - (asciis._A - 10); // 'B' => 66-(65-10)
if (ch >= asciis._a && ch <= asciis._f) return ch - (asciis._a - 10); // 'b' => 98-(97-10)
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)
return;
}

Expand Down

0 comments on commit 9574a28

Please sign in to comment.