2023-10-26 18:15:51 +00:00
|
|
|
|
# go-hexadeca
|
|
|
|
|
|
2023-10-27 18:00:18 +00:00
|
|
|
|
Package **hexadeca** implements **hexadecimal** _encoding_ and _decoding_, for the Go programming language.
|
2023-10-27 18:00:38 +00:00
|
|
|
|
This is meant to be a better alternative to Go's built-in `"hex"` package.
|
2023-10-26 18:15:51 +00:00
|
|
|
|
|
2023-10-28 18:48:19 +00:00
|
|
|
|
Package **hexadeca** does _not_ impose any endianness for hexadecimal encoding.
|
|
|
|
|
The individual symbols are returned separately. For example:
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-28 18:50:46 +00:00
|
|
|
|
b1, b0 := hexadeca.EncodeByteUsingUpperCaseSymbols(u8)
|
2023-10-28 18:50:16 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
b3, b2, b1, b0 := hexadeca.EncodeUint16UsingLowerCaseSymbols(u16)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-28 18:50:46 +00:00
|
|
|
|
r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint32UsingPersianSymbols(u32)
|
2023-10-28 18:48:19 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Package **hexadeca** has functions for hexadecimal encoding and decoding for the Go types:
|
2023-10-27 17:57:56 +00:00
|
|
|
|
* `byte` (i.e., `uint8`),
|
|
|
|
|
* `uint16`,
|
|
|
|
|
* `uint32`
|
|
|
|
|
* `uint64`
|
2023-10-28 20:35:39 +00:00
|
|
|
|
* `int8`
|
2023-10-28 19:02:30 +00:00
|
|
|
|
* `int16`
|
2023-10-28 18:58:30 +00:00
|
|
|
|
* `int32`
|
2023-10-27 17:57:56 +00:00
|
|
|
|
* `int64`
|
|
|
|
|
|
2023-10-26 18:15:51 +00:00
|
|
|
|
## Documention
|
|
|
|
|
|
2024-07-25 11:33:45 +00:00
|
|
|
|
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-hexadeca
|
2023-10-26 18:15:51 +00:00
|
|
|
|
|
2024-07-25 11:33:45 +00:00
|
|
|
|
[![GoDoc](https://godoc.org/github.com/reiver/go-hexadeca?status.svg)](https://godoc.org/github.com/reiver/go-hexadeca)
|
2023-10-26 18:15:51 +00:00
|
|
|
|
|
2023-10-27 18:15:26 +00:00
|
|
|
|
## Symbols
|
|
|
|
|
|
|
|
|
|
Package **hexadeca** lets you pick the 16 symbols to hexadecimal encode to and hexadecimal decode from.
|
|
|
|
|
|
2023-10-28 18:43:09 +00:00
|
|
|
|
Package **hexadeca** has built-in support for the following symbol sequences:
|
2023-10-27 20:34:50 +00:00
|
|
|
|
|
2023-10-28 04:56:11 +00:00
|
|
|
|
| Name | zero | one | two | three | four | five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen |
|
|
|
|
|
|------------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|--------|--------|----------|----------|---------|
|
|
|
|
|
| Lower-Case | `'0'` | `'1'` | `'2'` | `'3'` | `'4'` | `'5'` | `'6'` | `'7'` | `'8'` | `'9'` | `'a'` | `'b'` | `'c'` | `'d'` | `'e'` | `'f'` |
|
|
|
|
|
| Upper-Case | `'0'` | `'1'` | `'2'` | `'3'` | `'4'` | `'5'` | `'6'` | `'7'` | `'8'` | `'9'` | `'A'` | `'B'` | `'C'` | `'D'` | `'E'` | `'F'` |
|
|
|
|
|
| Persian | `'۰'` | `'۱'` | `'۲'` | `'۳'` | `'۴'` | `'۵'` | `'۶'` | `'۷'` | `'۸'` | `'۹'` | `'ی'` | `'ک'` | `'ل'` | `'م'` | `'ن'` | `'س'` |
|
2023-10-27 18:15:26 +00:00
|
|
|
|
|
2023-10-28 18:43:09 +00:00
|
|
|
|
Package **hexadeca** also lets you pick your own symbol sequences, using a function.
|
2023-10-27 20:34:50 +00:00
|
|
|
|
|
2023-10-28 20:44:32 +00:00
|
|
|
|
For example, one could create a symbol sequence function to make the hexadecimal encoding be:
|
|
|
|
|
|
|
|
|
|
| Name | zero | one | two | three | four | five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen |
|
|
|
|
|
|------------------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|--------|--------|----------|----------|---------|
|
|
|
|
|
| _Custom Example_ | `𝍠` | `𝍡` | `𝍢` | `𝍣` | `𝍤` | `𝍥` | `𝍦` | `𝍧` | `𝍨` | `𝍩` | `𝍪` | `𝍫` | `𝍬` | `𝍭` | `𝍮` | `𝍯` |
|
2023-10-28 21:03:29 +00:00
|
|
|
|
| _Custom Example_ | `❤️` | `💜` | `💙` | `💛` | `💚` | `🤍` | `🖤` | `🧡` | `🤎` | `💕` | `💔` | `💖` | `💗` | `💓` | `💞` | `💝` |
|
2023-10-28 20:44:32 +00:00
|
|
|
|
|
|
|
|
|
... or anything else.
|
|
|
|
|
|
2023-10-28 18:43:09 +00:00
|
|
|
|
### Samples
|
2023-10-27 20:34:50 +00:00
|
|
|
|
|
2023-10-28 18:43:09 +00:00
|
|
|
|
Here are some samples of hexadecimal numbers using each of the built-in symbol sequences:
|
|
|
|
|
|
|
|
|
|
| Name | Decimal 49,374 | Decimal 19,229 | Decimal 255 |
|
|
|
|
|
|------------|----------------|----------------|-------------|
|
|
|
|
|
| Lower-Case | `c0de` | `4b1d` | `ff` |
|
|
|
|
|
| Upper-Case | `C0DE` | `4B1D` | `FF` |
|
2023-10-28 18:44:36 +00:00
|
|
|
|
| Persian | `نم۰ل` | `م۱ک۴` | `'سس'` |
|
2023-10-27 20:34:50 +00:00
|
|
|
|
|
2023-10-27 20:36:28 +00:00
|
|
|
|
### Custom Symbols
|
|
|
|
|
|
2023-10-28 18:43:09 +00:00
|
|
|
|
Package **hexadeca** also lets you use your own custom symbols by using your own symbol function.
|
|
|
|
|
|
|
|
|
|
For example:
|
2023-10-27 18:15:26 +00:00
|
|
|
|
```go
|
|
|
|
|
func CustomSymbol(value byte) rune {
|
|
|
|
|
var table [16]rune = [16]rune{
|
|
|
|
|
'𝍠', // 0
|
|
|
|
|
'𝍡', // 1
|
|
|
|
|
'𝍢', // 2
|
|
|
|
|
'𝍣', // 3
|
|
|
|
|
'𝍤', // 4
|
|
|
|
|
'𝍥', // 5
|
|
|
|
|
'𝍦', // 6
|
|
|
|
|
'𝍧', // 7
|
|
|
|
|
'𝍨', // 8
|
|
|
|
|
'𝍩', // 9
|
|
|
|
|
'𝍪', // 10
|
|
|
|
|
'𝍫', // 11
|
|
|
|
|
'𝍬', // 12
|
|
|
|
|
'𝍭', // 13
|
|
|
|
|
'𝍮', // 14
|
|
|
|
|
'𝍯', // 15
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var index int = int(value) % len(table)
|
|
|
|
|
|
|
|
|
|
var result rune = table[index]
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
r1, r0 := hexadeca.EncodeRune(value, CustomSymbol)
|
|
|
|
|
```
|
|
|
|
|
|
2023-10-28 04:42:29 +00:00
|
|
|
|
Samples:
|
|
|
|
|
* `𝍬𝍠𝍭𝍮`
|
|
|
|
|
* `𝍤𝍫𝍡𝍭`
|
2023-10-27 20:36:28 +00:00
|
|
|
|
|
2023-10-26 18:15:51 +00:00
|
|
|
|
## Import
|
|
|
|
|
|
2023-10-27 04:47:35 +00:00
|
|
|
|
To import package **hexadeca** use `import` code like the following:
|
2023-10-26 18:15:51 +00:00
|
|
|
|
```
|
2024-07-25 11:33:45 +00:00
|
|
|
|
import "github.com/reiver/go-hexadeca"
|
2023-10-26 18:15:51 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
2023-10-26 23:55:58 +00:00
|
|
|
|
To install package **hexadeca** do the following:
|
2023-10-26 18:15:51 +00:00
|
|
|
|
```
|
2024-07-25 11:33:45 +00:00
|
|
|
|
GOPROXY=direct go get https://github.com/reiver/go-hexadeca
|
2023-10-26 18:15:51 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Author
|
|
|
|
|
|
2023-10-26 23:55:58 +00:00
|
|
|
|
Package **hexadeca** was written by [Charles Iliya Krempeaux](http://changelog.ca)
|