> Jeg har 4 enkeltstående bytes, der tilsammen udgør en floating point
> variable. Hvorfor jeg får det serveret som 4 byte kan jeg ikke lige svare
> på...
Hey
jeg er ikke sikker på det virker til det, men lavede noget endgang hvor jeg
modtog et float signal som 4 bytes over seriel porten, og den kode, skrevet
af en franskmand kunne gøre mit job... måske det er samme kodning som dit..
men det er desværre for længe siden ...
mvh
kasper
Function decodeIEEE(Car1, Car2, Car3, Car4 As Byte) As String
Dim decodeieee1 As Single
Dim signe As Integer
Dim exposant As Integer
Dim Mantisse As Single
If Car1 + Car2 + Car3 + Car4 = 0 Then
decodeieee1 = 0
Exit Function
End If
'** récupération du signe **
signe = 1
If Car1 And 128 Then signe = -1
'** récupération de l'exposant **
If Car1 And 64 Then exposant = 128
If Car1 And 32 Then exposant = exposant + 64
If Car1 And 16 Then exposant = exposant + 32
If Car1 And 8 Then exposant = exposant + 16
If Car1 And 4 Then exposant = exposant + 8
If Car1 And 2 Then exposant = exposant + 4
If Car1 And 1 Then exposant = exposant + 2
If Car2 And 128 Then exposant = exposant + 1
'** récupération de la mantisse **
If Car2 And 64 Then Mantisse = 2 ^ -1
If Car2 And 32 Then Mantisse = Mantisse + 2 ^ -2
If Car2 And 16 Then Mantisse = Mantisse + 2 ^ -3
If Car2 And 8 Then Mantisse = Mantisse + 2 ^ -4
If Car2 And 4 Then Mantisse = Mantisse + 2 ^ -5
If Car2 And 2 Then Mantisse = Mantisse + 2 ^ -6
If Car2 And 1 Then Mantisse = Mantisse + 2 ^ -7
If Car3 And 128 Then Mantisse = Mantisse + 2 ^ -8
If Car3 And 64 Then Mantisse = Mantisse + 2 ^ -9
If Car3 And 32 Then Mantisse = Mantisse + 2 ^ -10
If Car3 And 16 Then Mantisse = Mantisse + 2 ^ -11
If Car3 And 8 Then Mantisse = Mantisse + 2 ^ -12
If Car3 And 4 Then Mantisse = Mantisse + 2 ^ -13
If Car3 And 2 Then Mantisse = Mantisse + 2 ^ -14
If Car3 And 1 Then Mantisse = Mantisse + 2 ^ -15
If Car4 And 128 Then Mantisse = Mantisse + 2 ^ -16
If Car4 And 64 Then Mantisse = Mantisse + 2 ^ -17
If Car4 And 32 Then Mantisse = Mantisse + 2 ^ -18
If Car4 And 16 Then Mantisse = Mantisse + 2 ^ -19
If Car4 And 8 Then Mantisse = Mantisse + 2 ^ -20
If Car4 And 4 Then Mantisse = Mantisse + 2 ^ -21
If Car4 And 2 Then Mantisse = Mantisse + 2 ^ -22
If Car4 And 1 Then Mantisse = Mantisse + 2 ^ -23
decodeieee1 = ((1 + Mantisse) * 2 ^ (exposant - 127) * signe)
If Mid(decodeieee1, 4, 1) = "E" Or Mid(decodeieee1, 8, 1) = 0 Or
Mid(decodeieee1, 9, 1) = "E" Or Mid(decodeieee1, 2, 1) = "E" Then
decodeieee1 = decodeieee1 * 1000000000
decodeIEEE = Round(decodeieee1, 1) & " ns"
'Form1.Picture1.Print "Time/Div : " & Round(decodeIEEE, 1) & " ns"
GoTo sl
End If
If Mid(decodeieee1, 1, 1) <> 0 Then
decodeIEEE = decodeieee1 & " s"
'Form1.Picture1.Print "Time/Div : " & decodeIEEE & " s"
GoTo sl
End If
If Mid(decodeieee1, 3, 1) Then
decodeIEEE = decodeieee1 * 1000 & " ms"
'Form1.Picture1.Print "Time/Div : " & decodeIEEE * 1000 & " ms"
GoTo sl
End If
If Mid(decodeieee1, 3, 1) <> 0 Or Mid(decodeieee1, 4, 1) Or Mid(decodeieee1,
5, 1) <> 0 Then
decodeIEEE = decodeieee1 * 1000 & " ms"
'Form1.Picture1.Print "Time/Div : " & decodeIEEE * 1000 & " ms"
GoTo sl
End If
If Mid(decodeieee1, 6, 1) <> 0 Or Mid(decodeieee1, 7, 1) <> 0 Or
Mid(decodeieee1, 8, 1) <> 0 Then
decodeIEEE = Round(decodeieee1 * 1000000, 1) & " us"
'Form1.Picture1.Print "Time/Div : " & Round(decodeIEEE * 1000000, 1) & " us"
End If
sl:
End Function
|