summaryrefslogtreecommitdiff
path: root/internal/hex.go
blob: 62a818f955815426a8dabb59a618d611ec99ace4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package internal

const Hex = "0123456789abcdef"

func HexToInt(c rune) (byte, bool) {
	switch {
	case '0' <= c && c <= '9':
		return byte(c) - '0', true
	case 'a' <= c && c <= 'f':
		return byte(c) - 'a' + 10, true
	case 'A' <= c && c <= 'F':
		return byte(c) - 'A' + 10, true
	default:
		return 0, false
	}
}