Skip to content

Instantly share code, notes, and snippets.

@shockalotti
Created May 28, 2014 02:20
Show Gist options
  • Save shockalotti/8ce4a10d40cc28b3d73e to your computer and use it in GitHub Desktop.
Save shockalotti/8ce4a10d40cc28b3d73e to your computer and use it in GitHub Desktop.
Go Golang - halve integer
package main
import "fmt"
func halfNumber(x uint) (uint, bool){
if x % 2 == 0 {
return x/2, true
} else {
return x/2, false
}
}
func main() {
x := uint(7)
fmt.Println(halfNumber(x))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment