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-27 17:59:34 +00:00
|
|
|
|
Package **hexadeca** has functions for hexadecimal encoding and decoding with Go types:
|
2023-10-27 17:57:56 +00:00
|
|
|
|
* `byte` (i.e., `uint8`),
|
|
|
|
|
* `uint16`,
|
|
|
|
|
* `uint32`
|
|
|
|
|
* `uint64`
|
|
|
|
|
* `int64`
|
|
|
|
|
|
2023-10-26 18:15:51 +00:00
|
|
|
|
## Documention
|
|
|
|
|
|
|
|
|
|
Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-hexadeca
|
|
|
|
|
|
|
|
|
|
[![GoDoc](https://godoc.org/sourcecode.social/reiver/go-hexadeca?status.svg)](https://godoc.org/sourcecode.social/reiver/go-hexadeca)
|
|
|
|
|
|
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.
|
|
|
|
|
For example —
|
|
|
|
|
|
|
|
|
|
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 20:09:00 +00:00
|
|
|
|
`'۰'` [zero], `'۱'` [one], `'۲'` [two], `'۳'` [three], `'۴'` [four], `'۵'` [five], `'۶'` [six], `'۷'` [seven], `'۸'` [eight], `'۹'` [nine], `'ی'` (ye) [ten], `'ک'` (kāf) [eleven], `'ل'` (lâm) [twelve], `'م'` (mim) [thirteen], `'ن'` (nun) [fourteen], `'س' (sin) [fifteen]
|
2023-10-27 18:15:26 +00:00
|
|
|
|
|
|
|
|
|
As well as defining you own using function:
|
|
|
|
|
```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-27 18:28:29 +00:00
|
|
|
|
## hexadecimal encode `byte`
|
2023-10-27 00:01:40 +00:00
|
|
|
|
|
2023-10-27 18:23:51 +00:00
|
|
|
|
To hexadecimal encode a `byte` use any of these:
|
2023-10-27 05:01:30 +00:00
|
|
|
|
|
2023-10-27 00:01:40 +00:00
|
|
|
|
```go
|
2023-10-27 19:06:43 +00:00
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
2023-10-27 00:01:40 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==254 -> mostSignificant=='f', leastSignificant=='e'
|
|
|
|
|
mostSignificant, leastSignificant := hexadeca.EncodeByteUsingLowerCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==254 -> mostSignificant=='F', leastSignificant=='E'
|
|
|
|
|
mostSignificant, leastSignificant := hexadeca.EncodeByteUsingUpperCaseSymbols(value)
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:05:53 +00:00
|
|
|
|
import (
|
2023-10-27 19:06:43 +00:00
|
|
|
|
"sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
|
2023-10-27 19:05:53 +00:00
|
|
|
|
)
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==254 -> mostSignificant=='f', leastSignificant=='e'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
mostSignificant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.LowerCase)
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==254 -> mostSignificant=='F', leastSignificant=='E'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
mostSignificant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.UpperCase)
|
2023-10-27 18:23:51 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
## hexadecimal encode `uint16`
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
|
|
|
|
To hexadecimal encode a `uint16` use any of these:
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:06:43 +00:00
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
r3, r2, r1, r0 := hexadeca.EncodeUint16UsingLowerCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
r3, r2, r1, r0 := hexadeca.EncodeUint16UsingUpperCaseSymbols(value)
|
|
|
|
|
|
2023-10-27 00:01:40 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 18:23:51 +00:00
|
|
|
|
Or:
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:05:53 +00:00
|
|
|
|
import (
|
2023-10-27 19:06:43 +00:00
|
|
|
|
"sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
|
2023-10-27 19:05:53 +00:00
|
|
|
|
)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r3, r2, r1, r0 := hexadeca.EncodeUint16(value, runesymbols.LowerCase)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r3, r2, r1, r0 := hexadeca.EncodeUint16(value, runesymbols.UpperCase)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
## hexadecimal encode `uint32`
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
To hexadecimal encode a `uint32` use any of these:
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
```go
|
2023-10-27 19:06:43 +00:00
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
2023-10-27 18:28:29 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint32UsingLowerCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint32UsingUpperCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:05:53 +00:00
|
|
|
|
import (
|
2023-10-27 19:06:43 +00:00
|
|
|
|
"sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
|
2023-10-27 19:05:53 +00:00
|
|
|
|
)
|
2023-10-27 18:28:29 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint32(value, runesymbols.LowerCase)
|
2023-10-27 18:28:29 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint32(value, runesymbols.UpperCase)
|
2023-10-27 18:28:29 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## hexadecimal encode `uint64`
|
|
|
|
|
|
|
|
|
|
To hexadecimal encode a `uint64` use any of these:
|
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:06:43 +00:00
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='f', r14=='e', r13=='d', r12=='c', r11=='b', r10=='a', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint64UsingLowerCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='F', r14=='E', r13=='D', r12=='C', r11=='B', r10=='A', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint64UsingUpperCaseSymbols(value)
|
2023-10-27 18:23:51 +00:00
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Or:
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:05:53 +00:00
|
|
|
|
import (
|
2023-10-27 19:06:43 +00:00
|
|
|
|
"sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
|
2023-10-27 19:05:53 +00:00
|
|
|
|
)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
// value==18364758544493064720 -> r15=='f', r14=='e', r13=='d', r12=='c', r11=='b', r10=='a', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint64(value, runesymbols.LowerCase)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
// value==18364758544493064720 -> r15=='F', r14=='E', r13=='D', r12=='C', r11=='B', r10=='A', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeUint64(value, runesymbols.UpperCase)
|
2023-10-27 17:56:38 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
## hexadecimal encode `int64`
|
|
|
|
|
|
|
|
|
|
To hexadecimal encode a `int64` use any of these:
|
2023-10-27 17:56:38 +00:00
|
|
|
|
|
2023-10-27 18:28:29 +00:00
|
|
|
|
```go
|
2023-10-27 19:06:43 +00:00
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
2023-10-27 18:28:29 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='f', r14=='e', r13=='d', r12=='c', r11=='b', r10=='a', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeInt64UsingLowerCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='F', r14=='E', r13=='D', r12=='C', r11=='B', r10=='A', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeInt64UsingUpperCaseSymbols(value)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Or:
|
2023-10-27 05:01:30 +00:00
|
|
|
|
|
|
|
|
|
```go
|
2023-10-27 19:05:53 +00:00
|
|
|
|
import (
|
2023-10-27 19:06:43 +00:00
|
|
|
|
"sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
|
2023-10-27 19:05:53 +00:00
|
|
|
|
)
|
2023-10-27 05:01:30 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='f', r14=='e', r13=='d', r12=='c', r11=='b', r10=='a', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeInt64(value, runesymbols.LowerCase)
|
2023-10-27 05:01:30 +00:00
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// value==18364758544493064720 -> r15=='F', r14=='E', r13=='D', r12=='C', r11=='B', r10=='A', r9=='9', r8=='8', r7=='7', r6=='6', r5=='5', r4=='4', r3=='3', r2=='2', r1=='1', r0=='0'
|
2023-10-27 19:05:53 +00:00
|
|
|
|
r15, r14, r13, r12, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0 := hexadeca.EncodeInt64(value, runesymbols.UpperCase)
|
2023-10-27 05:01:30 +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
|
|
|
|
```
|
|
|
|
|
import "sourcecode.social/reiver/go-hexadeca"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
2023-10-26 23:55:58 +00:00
|
|
|
|
To install package **hexadeca** do the following:
|
2023-10-26 18:15:51 +00:00
|
|
|
|
```
|
2023-10-27 18:29:11 +00:00
|
|
|
|
GOPROXY=direct go get https://sourcecode.social/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)
|