Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nuriofernandez/radix-conversion
Go package to convert numbers from different base systems.
https://github.com/nuriofernandez/radix-conversion
base16 hexadecimal math radix
Last synced: 2 days ago
JSON representation
Go package to convert numbers from different base systems.
- Host: GitHub
- URL: https://github.com/nuriofernandez/radix-conversion
- Owner: nuriofernandez
- Created: 2024-08-18T16:57:30.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-08-21T07:59:36.000Z (3 months ago)
- Last Synced: 2024-09-18T10:11:06.396Z (about 2 months ago)
- Topics: base16, hexadecimal, math, radix
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Radix conversion
This package is a project to convert numbers from different base systems.
It allows to specify the radix of a base and define your custom character mapping.
# Decimal (b10) to Hexadecimal (b16) example:
### Definition of the base systems:
```go
var Decimal = base.Base{
Name: "Base 10",
Characters: map[int]rune{
0: '0',
1: '1',
2: '2',
3: '3',
4: '4',
5: '5',
6: '6',
7: '7',
8: '8',
9: '9',
},
Radix: 10,
}
``````go
var Hexadecimal = base.Base{
Name: "Hexadecimal",
Characters: map[int]rune{
0: '0',
1: '1',
2: '2',
3: '3',
4: '4',
5: '5',
6: '6',
7: '7',
8: '8',
9: '9',
10: 'A',
11: 'B',
12: 'C',
13: 'D',
14: 'E',
15: 'F',
},
Radix: 16,
}
```### Operation
```go
decimal := number.Number{
Value: "894",
Base: bases.Decimal,
}hex := decimal.ConvertTo(bases.Hexadecimal)
fmt.Println("Result is: " + hex.Value)
```#### Output:
> Result is: 37E