MCPcopy
hub / github.com/lifei6671/interview-go / ipToInt

Function ipToInt

algorithm/ip-start-end-query.go:68–79  ·  view source on GitHub ↗
(ip string)

Source from the content-addressed store, hash-verified

66}
67
68func ipToInt(ip string) int {
69 ips := strings.Split(ip, ".")
70 ipInt := 0
71 var pos uint = 24
72 for _, ipItem := range ips {
73 ipint, _ := strconv.Atoi(ipItem)
74 ipint = ipint << pos
75 ipInt = ipInt | ipint
76 pos -= 8
77 }
78 return ipInt
79}
80func init() {
81 var err error
82 err = initIPAddress()

Callers 2

queryFunction · 0.85
initIPAddressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected