1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2022-11-18 16:53:59 +08:00
parent 6e24cf5bdc
commit b76be4ce6b
17 changed files with 103 additions and 180 deletions

View File

@ -5,10 +5,21 @@ import (
"encoding/hex"
)
const hextable = "0123456789ABCDEF"
const hexTable = "0123456789ABCDEF"
type BytesResult []byte
// FromHexString 从十六进制获取
func FromHexString(s string) (BytesResult, error) {
b, err := hex.DecodeString(s)
return BytesResult(b), err
}
func FromBase64String(s string) (BytesResult, error) {
b, err := base64.StdEncoding.DecodeString(s)
return BytesResult(b), err
}
func (r BytesResult) Hex() string {
return hex.EncodeToString(r)
}
@ -19,8 +30,8 @@ func (r BytesResult) UppercaseHex() string {
re := r[:]
for _, v := range re {
dst[j] = hextable[v>>4]
dst[j+1] = hextable[v&0x0f]
dst[j] = hexTable[v>>4]
dst[j+1] = hexTable[v&0x0f]
j += 2
}