Documentation
¶
Index ¶
- func B1(n uint8) []byte
- func B2(n uint16) []byte
- func B4(n uint32) []byte
- func B8(n uint64) []byte
- func I16(b []byte) int16
- func I32(b []byte) int32
- func I64(b []byte) int64
- func I8(b []byte) int8
- func Q1(n int8) []byte
- func Q2(n int16) []byte
- func Q4(n int32) []byte
- func Q8(n int64) []byte
- func U16(b []byte) uint16
- func U32(b []byte) uint32
- func U64(b []byte) uint64
- func U8(b []byte) uint8
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func B4 ¶
B4 converts a uint32 number into a big-endian byte slice of length 4.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { n := uint32(16909060) fmt.Printf("%x\n", numx.B4(n)) }
Output: 01020304
func B8 ¶
B8 converts a uint64 number into a big-endian byte slice of length 8.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { n := uint64(72623859790382856) fmt.Printf("%x\n", numx.B8(n)) }
Output: 0102030405060708
func I64 ¶
I64 converts a big-endian byte slice to an int64 number. It processes up to the first 8 bytes and handles signed integers.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { b := []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} fmt.Println(numx.I64(b)) // Signed negative }
Output: -1
func Q8 ¶
Q8 converts an int64 number into a big-endian byte slice of length 8. It handles both positive and negative numbers using 2's complement.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { n := int64(-1) fmt.Printf("%x\n", numx.Q8(n)) }
Output: ffffffffffffffff
func U32 ¶
U32 converts a big-endian byte slice to a uint32 number.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { b := []byte{0x01, 0x02, 0x03, 0x04} fmt.Println(numx.U32(b)) }
Output: 16909060
func U64 ¶
U64 converts a big-endian byte slice to a uint64 number. It processes up to the first 8 bytes of the slice.
Example ¶
package main import ( "fmt" "github.com/exonlabs/go-utils/pkg/abc/numx" ) func main() { b := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} fmt.Println(numx.U64(b)) }
Output: 72623859790382856
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.