Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Created May 27, 2023 06:01
Show Gist options
  • Save RealYukiSan/0cfae0cb6fc36bafd9efe8ad72dacfa8 to your computer and use it in GitHub Desktop.
Save RealYukiSan/0cfae0cb6fc36bafd9efe8ad72dacfa8 to your computer and use it in GitHub Desktop.
Get max decimal of binary in golang
package main
import (
"fmt"
"math"
)
func main() {
binaryLength := 8
var maxValueInDecimal float64 = 0
var binary2decimal []float64
for i := 0; i < binaryLength; i++ {
binary2decimal = append(binary2decimal, math.Pow(2, float64(i)))
}
for _, num := range binary2decimal {
maxValueInDecimal += num
}
fmt.Println(maxValueInDecimal)
fmt.Println(binary2decimal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment