Created
April 19, 2021 13:37
-
-
Save Yuuki77/341686530626b45fae68f0233021b1ed to your computer and use it in GitHub Desktop.
base2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func keta(n int) int { | |
keta := 0 | |
for n > 0 { | |
n /= 10 | |
keta++ | |
} | |
return keta | |
} | |
func main() { | |
k := 1011 | |
ans := 0.0 | |
keta := keta(k) | |
for i := 0; i < keta; i++ { | |
val := k % 10 | |
ans += math.Pow(2, float64(i)) * float64(val) | |
k /= 10 | |
} | |
fmt.Println("ans", ans) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment