deno.land / x / masx200_leetcode_test@10.6.5 / convert-a-number-to-hexadecimal / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export default function toHex(num: number): string { const CONV = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", ];
const ans: string[] = []; if (num < 0) { num += 2 ** 32; } for (let i = 0; i < 8; i++) { ans.push(CONV[num % 16]); num = Math.floor(num / 16); if (num == 0) { break; } } ans.reverse(); return ans.join("");}
masx200_leetcode_test

Version Info

Tagged at
a year ago