Add util funciton to format as hex

This commit is contained in:
David Lechner
2020-05-26 21:20:08 -05:00
committed by David Lechner
parent 7a7eba407f
commit 6713afe198
3 changed files with 14 additions and 12 deletions
+9
View File
@@ -13,3 +13,12 @@ export function assert(condition: boolean, message: string): void {
throw Error(message);
}
}
/**
* Formats a number as hex (0x00...)
* @param n The number to format
* @param pad The total number of digits padded with leading 0s
*/
export function hex(n: number, pad: number): string {
return `0x${n.toString(16).padStart(pad, '0')}`;
}