-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendian_le.go
55 lines (47 loc) · 1.45 KB
/
endian_le.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
// endian_le.go -- endian conversion routines for little-endian arch.
// This file is for little endian systems; thus conversion _to_ little-endian
// format is idempotent.
// We build this file into all arch's that are LE. We list them in the build
// constraints below
//
// (c) Sudhi Herle 2018
//
// Author: Sudhi Herle <[email protected]>
//
// This software does not come with any express or implied
// warranty; it is provided "as is". No claim is made to its
// suitability for any purpose.
// +build 386 amd64 arm arm64 ppc64le mipsle mips64le
package chd
func toLittleEndianUint64(v uint64) uint64 {
return v
}
func toLittleEndianUint32(v uint32) uint32 {
return v
}
func toLittleEndianUint16(v uint16) uint16 {
return v
}
// From LE -> BE: swap bytes all the way around
func toBigEndianUint64(v uint64) uint64 {
return ((v & 0x00000000000000ff) << 56) |
((v & 0x000000000000ff00) << 40) |
((v & 0x0000000000ff0000) << 24) |
((v & 0x00000000ff000000) << 8) |
((v & 0x000000ff00000000) >> 8) |
((v & 0x0000ff0000000000) >> 24) |
((v & 0x00ff000000000000) >> 40) |
((v & 0xff00000000000000) >> 56)
}
// From LE -> BE: swap bytes all the way around
func toBigEndianUint32(v uint32) uint32 {
return ((v & 0x000000ff) << 24) |
((v & 0x0000ff00) << 8) |
((v & 0x00ff0000) >> 8) |
((v & 0xff000000) >> 24)
}
// From LE -> BE: swap bytes all the way around
func toBigEndianUint16(v uint16) uint16 {
return ((v & 0x00ff) << 8) |
((v & 0xff00) >> 8)
}