All Articles

How to convert IPv4 and IPv6 to integer

Sometimes we need to convert IPv4/IPv6 to integer/decimal for storing purposes. It allows the creation of more efficient database indexes and filter values faster.

Here is how we could do it in a few lines of code in golang:

package main

import (

func Ip2Int(ip net.IP) *big.Int {
	i := big.NewInt(0)
	return i

func main() {

Play with code

Share your thoughts 😉

Happy coding! 🚀

Published Nov 23, 2021

Passionate software engineer with expertise in software development, microservice architecture, and cloud infrastructure.