7 个解决方案
#1
把float变成string,然后一个一个字符取,再转到int,把int变成byte,根据float变byte的规率(或算法)合成byte[]
#2
楼主的意思是不是:
float f = ……;
char *p = (char *)&f;
float f = ……;
char *p = (char *)&f;
#3
能不能写详细点啊
#4
在VB中呢
#5
能不能用APi函数
#6
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click() '双精度
Dim a As Double
Dim buff() As Byte
ReDim buff(7)
a = 12345.6789
CopyMemory buff(0), a, 8 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Double
CopyMemory b, buff(0), 8 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Sub Command2_Click() '单精度
Dim a As Single
Dim buff() As Byte
ReDim buff(3)
a = 12345.6789
Debug.Print a
CopyMemory buff(0), a, 4 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Single
CopyMemory b, buff(0), 4 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click() '双精度
Dim a As Double
Dim buff() As Byte
ReDim buff(7)
a = 12345.6789
CopyMemory buff(0), a, 8 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Double
CopyMemory b, buff(0), 8 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Sub Command2_Click() '单精度
Dim a As Single
Dim buff() As Byte
ReDim buff(3)
a = 12345.6789
Debug.Print a
CopyMemory buff(0), a, 4 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Single
CopyMemory b, buff(0), 4 '将字节数组转为Double型变量
Debug.Print b
End Sub
#7
咳,注释忘了改,自己改回来吧
#1
把float变成string,然后一个一个字符取,再转到int,把int变成byte,根据float变byte的规率(或算法)合成byte[]
#2
楼主的意思是不是:
float f = ……;
char *p = (char *)&f;
float f = ……;
char *p = (char *)&f;
#3
能不能写详细点啊
#4
在VB中呢
#5
能不能用APi函数
#6
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click() '双精度
Dim a As Double
Dim buff() As Byte
ReDim buff(7)
a = 12345.6789
CopyMemory buff(0), a, 8 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Double
CopyMemory b, buff(0), 8 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Sub Command2_Click() '单精度
Dim a As Single
Dim buff() As Byte
ReDim buff(3)
a = 12345.6789
Debug.Print a
CopyMemory buff(0), a, 4 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Single
CopyMemory b, buff(0), 4 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click() '双精度
Dim a As Double
Dim buff() As Byte
ReDim buff(7)
a = 12345.6789
CopyMemory buff(0), a, 8 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Double
CopyMemory b, buff(0), 8 '将字节数组转为Double型变量
Debug.Print b
End Sub
Private Sub Command2_Click() '单精度
Dim a As Single
Dim buff() As Byte
ReDim buff(3)
a = 12345.6789
Debug.Print a
CopyMemory buff(0), a, 4 '将Double型变量转为字节数组
Dim i As Long
For i = 0 To UBound(buff)
Debug.Print buff(i)
Next
Dim b As Single
CopyMemory b, buff(0), 4 '将字节数组转为Double型变量
Debug.Print b
End Sub
#7
咳,注释忘了改,自己改回来吧