Created
September 6, 2019 23:25
-
-
Save joshuaaguilar20/fa36922b3a7198e3d280a14446ef368d to your computer and use it in GitHub Desktop.
Bit Shifting Iota
This file contains hidden or 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
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