-
Notifications
You must be signed in to change notification settings - Fork 0
/
intutils.go
112 lines (80 loc) · 1.85 KB
/
intutils.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package hexutils
import (
//"fmt"
)
//MakeUInt16BE makes uint16 from byte array
func MakeUInt16BE(aBytes [2]byte) uint16 {
lRet := uint16(0)
lRet = uint16(aBytes[0])
lRet = lRet << 8
lRet |= uint16(aBytes[1])
return lRet
}
//MakeUInt16LE makes uint16 from byte array
func MakeUInt16LE(aBytes [2]byte) uint16 {
lRet := uint16(0)
lRet = uint16(aBytes[1])
lRet = lRet << 8
lRet |= uint16(aBytes[0])
return lRet
}
//MakeUInt32FromUInt16 makes uint32 from two uint16
func MakeUInt32FromUInt16(aHi, aLo uint16) uint32 {
lRet := uint32(0)
lRet = uint32(aHi)
lRet = lRet << 16
lRet |= uint32(aLo)
return lRet
}
func MakeUInt32FromUInt8(aB3, aB2, aB1, aB0 uint8) uint32 {
lRet := uint32(0)
lRet |= uint32(aB3)
lRet <<= 8
lRet |= uint32(aB2)
lRet <<= 8
lRet |= uint32(aB1)
lRet <<= 8
lRet |= uint32(aB0)
return lRet
}
func MakeUInt32FromByte(aB3, aB2, aB1, aB0 byte) uint32 {
lRet := uint32(0)
lRet |= uint32(aB3)
lRet <<= 8
lRet |= uint32(aB2)
lRet <<= 8
lRet |= uint32(aB1)
lRet <<= 8
lRet |= uint32(aB0)
return lRet
}
func GetByte0FromUInt32(aData uint32) byte {
return byte(aData & 0xFF)
}
func GetByte1FromUInt32(aData uint32) byte {
return byte((aData >> 8) & 0xFF)
}
func GetByte2FromUInt32(aData uint32) byte {
return byte((aData >> 16) & 0xFF)
}
func GetByte3FromUInt32(aData uint32) byte {
return byte((aData >> 24) & 0xFF)
}
func GetUInt80FromUInt32(aData uint32) uint8 {
return uint8(aData & 0xFF)
}
func GetUInt81FromUInt32(aData uint32) uint8 {
return uint8((aData >> 8) & 0xFF)
}
func GetUInt82FromUInt32(aData uint32) uint8 {
return uint8((aData >> 16) & 0xFF)
}
func GetUInt83FromUInt32(aData uint32) uint8 {
return uint8((aData >> 24) & 0xFF)
}
func GetUInt160FromUInt32(aData uint32) uint16 {
return uint16(aData & 0xFFFF)
}
func GetUInt161FromUInt32(aData uint32) uint16 {
return uint16((aData >> 16) & 0xFFFF)
}