You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
981 B
Python
41 lines
981 B
Python
7 months ago
|
import struct
|
||
|
|
||
|
# 大端模式
|
||
|
def floatToABCD(value):
|
||
|
valueByte = struct.unpack('>HH',struct.pack('>f', value))
|
||
|
return valueByte
|
||
|
|
||
|
# 小端模式
|
||
|
def floatToDCBA(value):
|
||
|
valueByte = struct.unpack('>HH', struct.pack('<f', value))
|
||
|
return valueByte
|
||
|
|
||
|
# 单字反转
|
||
|
def floatToBADC(value):
|
||
|
valueByte = struct.unpack('<HH', struct.pack('>f', value))
|
||
|
return valueByte
|
||
|
|
||
|
# 双字反转
|
||
|
def floatToCDAB(value):
|
||
|
valueByte = struct.unpack('<HH', struct.pack('<f', value))
|
||
|
return valueByte
|
||
|
|
||
|
|
||
|
def ABCDToFloat(value):
|
||
|
valueByte = struct.unpack('>f',struct.pack('>HH', value[0], value[1]))
|
||
|
return valueByte[0]
|
||
|
|
||
|
# 小端模式
|
||
|
def DCBAToFloat(value):
|
||
|
valueByte = struct.unpack('<f', struct.pack('>HH', value[0], value[1]))
|
||
|
return valueByte[0]
|
||
|
|
||
|
def BADCToFloat(value):
|
||
|
valueByte = struct.unpack('>f', struct.pack('<HH', value[0], value[1]))
|
||
|
return valueByte[0]
|
||
|
|
||
|
|
||
|
def CDABToFloat(value):
|
||
|
valueByte = struct.unpack('<f', struct.pack('<HH', value[0], value[1]))
|
||
|
return valueByte[0]
|