forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers.go
52 lines (44 loc) · 864 Bytes
/
numbers.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
package serial
import (
"strconv"
)
func Uint16ToBytes(value uint16) []byte {
return []byte{byte(value >> 8), byte(value)}
}
func Uint16ToString(value uint16) string {
return strconv.Itoa(int(value))
}
func Uint32ToBytes(value uint32) []byte {
return []byte{
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
func IntToBytes(value int) []byte {
return []byte{
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
func IntToString(value int) string {
return Int64ToString(int64(value))
}
func Int64ToBytes(value int64) []byte {
return []byte{
byte(value >> 56),
byte(value >> 48),
byte(value >> 40),
byte(value >> 32),
byte(value >> 24),
byte(value >> 16),
byte(value >> 8),
byte(value),
}
}
func Int64ToString(value int64) string {
return strconv.FormatInt(value, 10)
}