I wrote a stupid solution for this, the best recipe? As you can see a lot of useless conversions.
package main import ( "fmt" "strconv" "math" ) func conv(str string) int { l := len(str) result := 0.0 for i,n := range str { number,_ := strconv.Atof64(string(n)) result += math.Exp2(float64(li-1))*number } return int(result) } func main() { fmt.Println(conv("1001")) }
source share