summaryrefslogtreecommitdiffstats
path: root/enc/hex.go
blob: 0d1953878cfdfe75bfc8e5866e6b5469e2bbfcdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright © 2020 rsiddharth <s@ricketyspace.net>
// SPDX-License-Identifier: ISC

package enc

// Adapted from
// https://go.googlesource.com/go/+/refs/tags/go1.15/src/encoding/hex/hex.go#83
func HexCharToDec(c byte) uint16 {
	switch {
	case '0' <= c && c <= '9':
		return uint16(c - '0')
	case 'a' <= c && c <= 'f':
		return uint16(c - 'a' + 10)
	}
	return 0
}