https://github.com/hekmon/cunits
ComputerUnits allows to manipulate binary and decimal representations of bits and bytes
https://github.com/hekmon/cunits
binary bits bytes decimal golang golang-library units
Last synced: 5 months ago
JSON representation
ComputerUnits allows to manipulate binary and decimal representations of bits and bytes
- Host: GitHub
- URL: https://github.com/hekmon/cunits
- Owner: hekmon
- License: mit
- Created: 2018-03-31T11:59:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-09-28T19:39:33.000Z (5 months ago)
- Last Synced: 2025-10-10T11:34:36.204Z (5 months ago)
- Topics: binary, bits, bytes, decimal, golang, golang-library, units
- Language: Go
- Size: 36.1 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ComputerUnits
[](https://pkg.go.dev/github.com/hekmon/cunits/v3)
ComputerUnits allows to manipulate binary and decimal representations of bits and bytes.
## Installation
```bash
go get -u github.com/hekmon/cunits/v3
```
## Usage
### Constants example
```golang
fmt.Println(cunits.Kb)
fmt.Println(cunits.Kib)
fmt.Println(cunits.KB)
fmt.Println(cunits.KiB)
fmt.Printf("1000 MiB = %f MB\n", float64(1000)*cunits.MiB/cunits.MB)
```
will output:
```text
1000
1024
8000
8192
1000 MiB = 1048.576000 MB
```
### Custom type example
```golang
size := cunits.Bits(58) * cunits.MiB
fmt.Println(size.Mb())
fmt.Println(size.GiBString())
```
will output:
```text
486.539264
0.06 GiB
```
### Parsing example
```golang
size, err := cunits.Parse("7632 MiB")
if err != nil {
panic(err)
}
fmt.Println(size)
fmt.Println(size.KiB())
fmt.Println(size.KbString())
```
will output:
```text
7.45 GiB
7.815168e+06
64021856.26 Kbit
```