...
Source file
src/os/str.go
Documentation: os
1
2
3
4
5
6
7 package os
8
9
10 func itox(val int) string {
11 if val < 0 {
12 return "-" + uitox(uint(-val))
13 }
14 return uitox(uint(val))
15 }
16
17 const hex = "0123456789abcdef"
18
19
20 func uitox(val uint) string {
21 if val == 0 {
22 return "0x0"
23 }
24 var buf [20]byte
25 i := len(buf) - 1
26 for val >= 16 {
27 q := val / 16
28 buf[i] = hex[val%16]
29 i--
30 val = q
31 }
32
33 buf[i] = hex[val%16]
34 i--
35 buf[i] = 'x'
36 i--
37 buf[i] = '0'
38 return string(buf[i:])
39 }
40
View as plain text