Skip to content

Instantly share code, notes, and snippets.

@joshuaaguilar20
Created September 6, 2019 23:25
Show Gist options
  • Save joshuaaguilar20/fa36922b3a7198e3d280a14446ef368d to your computer and use it in GitHub Desktop.
Save joshuaaguilar20/fa36922b3a7198e3d280a14446ef368d to your computer and use it in GitHub Desktop.
Bit Shifting Iota
func main() {
iotatoKb()
}
func iotatoKb(){
const (
_ = iota
kb = 1 << (iota * 10)
mb = 1 << (iota * 10)
gb = 1 << (iota * 10)
)
fmt.Printf("%d\t\t%b\n", kb, mb)
fmt.Printf("%d\t\t%b\n", mb, gb)
fmt.Printf("%d\t%b\n", gb, gb)
}
func bytesToMb(){
kb:= 1024
mb:= 1024 * kb
gb:= 1024 * mb
fmt.Printf("%d\t\t%b\n", kb, mb)
fmt.Printf("%d\t\t%b\n", mb, gb)
fmt.Printf("%d\t%b\n", gb, gb)
}
func printBits(){
x:= 4
fmt.Printf("%d\t\t%b\n", x, x)
y:= x << 1
fmt.Printf("%d\t\t%b", y,y)
/*
Output
4 100
8 1000
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment