Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 30-Aug-2019 | - | ||||
cunits-2.0.1/ | H | 10-Jun-2019 | - | 901 | 562 | |
.gitignore | H A D | 30-Aug-2019 | 275 | 15 | 11 | |
LICENSE | H A D | 30-Aug-2019 | 1 KiB | 22 | 17 | |
README.md | H A D | 30-Aug-2019 | 904 | 61 | 46 | |
bits.go | H A D | 30-Aug-2019 | 9.8 KiB | 425 | 249 | |
consts.go | H A D | 30-Aug-2019 | 1.9 KiB | 85 | 42 | |
import.go | H A D | 30-Aug-2019 | 6.6 KiB | 293 | 197 |
README.md
1# ComputerUnits 2 3[![GoDoc](https://godoc.org/github.com/hekmon/cunits?status.svg)](https://godoc.org/github.com/hekmon/cunits) 4 5ComputerUnits allows to manipulate binary and decimal representations of bits and bytes. 6 7## Constants example 8 9```golang 10fmt.Println(cunits.Kbit) 11fmt.Println(cunits.Kibit) 12fmt.Println(cunits.KB) 13fmt.Println(cunits.KiB) 14fmt.Printf("1000 MiB = %f MB\n", float64(1000)*cunits.MiB/cunits.MB) 15``` 16 17will output: 18 19``` 201000 211024 228000 238192 241000 MiB = 1048.576000 MB 25``` 26 27## Custom type example 28 29```golang 30size := cunits.Bit(58) * cunits.MiB 31fmt.Println(size.Mbit()) 32fmt.Println(size.GiBString()) 33``` 34 35will output: 36 37``` 38486.539264 390.06 GiB 40``` 41 42## Parsing example 43 44```golang 45size, err := cunits.Parse("7632 MiB") 46if err != nil { 47 panic(err) 48} 49fmt.Println(size) 50fmt.Println(size.KiB()) 51fmt.Println(size.KbitString()) 52``` 53 54will output: 55 56``` 577.45 GiB 587.815168e+06 5964021856.26 Kbit 60``` 61