• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D10-Jun-2019275 1511

LICENSEH A D10-Jun-20191 KiB2217

README.mdH A D10-Jun-2019904 6146

bits.goH A D10-Jun-20199.8 KiB425249

consts.goH A D10-Jun-20191.9 KiB8542

import.goH A D10-Jun-20196.6 KiB293197

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