-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbyte.go
67 lines (48 loc) · 1000 Bytes
/
byte.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package asdf
func IsByteUpper(b byte) bool {
return b >= 'A' && b <= 'Z'
}
func IsByteLower(b byte) bool {
return b >= 'a' && b <= 'z'
}
func IsByteNumber(b byte) bool {
return b >= '0' && b <= '9'
}
func IsByteUnder(b byte) bool {
return b == '_'
}
func GetBytes(bin []byte, offset, size int) ([]byte, int) {
end := offset + size
return bin[offset:end], end
}
func CloneBytes(bin []byte) []byte {
obj := make([]byte, len(bin))
copy(obj, bin)
return obj
}
func ByteReverse(bin []byte) {
count := len(bin)
if count > 1 {
for i := 0; i < count/2; i++ {
bin[i], bin[count-i] = bin[count-i], bin[i]
}
}
}
type Byte byte
func MakeByte(high, low int) Byte {
return Byte((high << 4) | low)
}
func (me Byte) SetHigh(high int) Byte {
low := me.Low()
return MakeByte(high, low)
}
func (me Byte) SetLow(low int) Byte {
high := me.High()
return MakeByte(high, low)
}
func (me Byte) High() int {
return int(me >> 4)
}
func (me Byte) Low() int {
return int(me & 0xf)
}