gomathbits

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

README

gomathbits

数据类型强制转换

在嵌入式领域中,对协议进行数据解析时经常需要进行字节流(小端模式)截取和数据类型相互转换

本代码封装了C语言类型和GO语言基本数据类型的相互转换

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteString

func ByteString(p []byte) string

ByteString byte to string except 0

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte

BytesCombine combine the byte array

func BytesToString

func BytesToString(b []byte) string

BytesToString 字节流转字符串

func BytesToStringPerf

func BytesToStringPerf(b []byte) string

BytesToStringPerf 字节流转字符串,性能优化版

func BytesToUint16

func BytesToUint16(bits []byte) (u uint16, err error)

BytesToUint16 return uint16 from bits

func BytesToUint32

func BytesToUint32(bits []byte) (u uint32, err error)

BytesToUint32 return uint32 from bits

func BytesToUint64

func BytesToUint64(bits []byte) (u uint64, err error)

BytesToUint64 return uint64 from bits

func BytesToUint8

func BytesToUint8(bits []byte) (u uint8, err error)

BytesToUint8 return uint8 from bits

func EncodeToString

func EncodeToString(b []byte) string

EncodeToString returns the hexadecimal encoding of b.

func Float32bits

func Float32bits(f float32) uint32

Float32bits returns the IEEE 754 binary representation of f.

func Float32frombits

func Float32frombits(b uint32) float32

Float32frombits returns the floating point number corresponding to the IEEE 754 binary representation b.

func Float64bits

func Float64bits(f float64) uint64

Float64bits returns the IEEE 754 binary representation of f.

func Float64frombits

func Float64frombits(b uint64) float64

Float64frombits returns the floating point number corresponding the IEEE 754 binary representation b.

func Int16bits

func Int16bits(i int16) uint16

Int16bits returns uint16

func Int16frombits

func Int16frombits(b uint16) int16

Int16frombits return int16

func Int32bits

func Int32bits(i int32) uint32

Int32bits returns uint32

func Int32frombits

func Int32frombits(b uint32) int32

Int32frombits return int32

func Int64bits

func Int64bits(i int64) uint64

Int64bits returns uint64

func Int64frombits

func Int64frombits(b uint64) int64

Int64frombits return int64

func Int8bits

func Int8bits(i int8) uint8

Int8bits returns uint8

func Int8frombits

func Int8frombits(b uint8) int8

Int8frombits return int8

func ParseFloat

func ParseFloat(s string, bitSize int) (f float64, err error)

ParseFloat converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64. When bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value.

If s is well-formed and near a valid floating point number, ParseFloat returns the nearest floating point number rounded using IEEE754 unbiased rounding.

func ParseFloat32

func ParseFloat32(s string) (f float32, err error)

ParseFloat32 converts the string s to a floating-point number with the precision specified by 32 for float32

func ParseFloat64

func ParseFloat64(s string) (f float64, err error)

ParseFloat64 converts the string s to a floating-point number with the precision specified by 64 for float64

func ParseInt

func ParseInt(s string, bitSize int) (i int64, err error)

ParseInt parse hexadecimal encoding of string to int64 The bitSize argument specifies the integer type that the result must fit into. Bit sizes 8, 16, 32, and 64 correspond to int8, int16, int32, and int64.

func ParseUInt

func ParseUInt(s string, bitSize int) (u uint64, err error)

ParseUInt parse hexadecimal encoding of string to uint64 The bitSize argument specifies the integer type that the result must fit into. Bit sizes 8, 16, 32, and 64 correspond to uint8, uint16, uint32, and uint64.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes 字符串转字节流

func StringToBytesPerf

func StringToBytesPerf(s string) []byte

StringToBytesPerf 字符串转字节流, 性能优化版

func Uint16ToBytes

func Uint16ToBytes(u uint16) []byte

Uint16ToBytes returns bytes

func Uint32ToBytes

func Uint32ToBytes(u uint32) []byte

Uint32ToBytes returns bytes

func Uint64ToBytes

func Uint64ToBytes(u uint64) []byte

Uint64ToBytes returns bytes

func Uint8ToBytes

func Uint8ToBytes(u uint8) []byte

Uint8ToBytes returns bytes

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL