Format IEEE 754 (32-bit)

Résolu
gallyhc Messages postés 386 Date d'inscription samedi 4 octobre 2008 Statut Membre Dernière intervention 19 février 2018 - 10 juin 2002 à 08:47
cs_bedu Messages postés 3 Date d'inscription lundi 10 juillet 2006 Statut Membre Dernière intervention 30 novembre 2010 - 30 nov. 2010 à 12:08
Bonjour,

Cela fait deja le 3eme messages que je mes ici :sad) ( :big) ce n'est pas une critique :big) ), je me dit que ci il n'y a pas réponce c'est que personne n'a de solution.

En fait ce que je voudrais c'est 2 fonctions avec la conversion du format IEEE 754 vers une valeur décimal et vis serva...

Merci d'avance de votre aide.
A++
Gally Home Corp.

2 réponses

cs_Hbar Messages postés 1 Date d'inscription vendredi 16 août 2002 Statut Membre Dernière intervention 18 août 2002 1
18 août 2002 à 23:14
Je vient de tomber sur ta demande, s'il n'est pas trop tard voiçi un bout de code qui j'espere te conviendra. Ce sont deux fonctions qui permettent de coder ou décoder un flottant au format IEEE 754. ces deux fonctions fonctionnent correctement, il faut juste y ajouter un contrôle de dépassement de capacité. Bien que cette solution fonctionne elle ne me satisfait pas vraiment, je trouve qu'il y a trop de ligne de code. si tu trouve une autre solution en VB je suis preneur!

Ce codage/décodage est vraiment tres simple à réaliser en C (environ une ligne de code par fonction !!). Je pense que la solution la meilleur serai de réaliser une DLL en C, mais hélas je suis incapable de la réaliser. Si tu connait quelqu'un capable de réaliser cette dll, fait moi signe.

Cordialement.
Hervé

Private Function CodageIEEE(Nombre As Double) As Byte
Dim i, j, Index, Mantisse As Integer
Dim Resultat As Double
Dim bit(0 To 31) As Byte
'Nombre = 1
CodageIEEE = 0
'** Initialisation des bits à zéro **
For i = 0 To 31
bit(i) = 0
Next
'** Calcul de signe
If Nombre < 0 Then
Nombre = Nombre * -1
bit(31) = 1
End If

' ** Calcul de la Exposant **
'i = 0
'Do
'i = i + 1
For i = 0 To 255
If Nombre > 1 Then
Resultat = Nombre / 2 ^ i
If Resultat < 2 Then
Mantisse = 127 + i
i = 255
'Exit Do
End If
Else
Resultat = Nombre * 2 ^ i
If ((Resultat >= 1) And (Resultat < 2)) Then
Mantisse = 127 - i
i = 255
'Exit Do
End If
End If
Next
'Loop

If (Mantisse And 1) = 1 Then
bit(23) = 1
End If

If (Mantisse And 2) = 2 Then
bit(24) = 1
End If

If (Mantisse And 4) = 4 Then
bit(25) = 1
End If
If (Mantisse And 8) = 8 Then
bit(26) = 1
End If
If (Mantisse And 16) = 16 Then
bit(27) = 1
End If

If (Mantisse And 32) = 32 Then
bit(28) = 1
End If

If (Mantisse And 64) = 64 Then
bit(29) = 1
End If

If (Mantisse And 128) = 128 Then
bit(30) = 1
End If

' ** fin de calcul de la mantisse **
If Resultat >= 1 Then
Nombre = Resultat - 1
For i = 0 To 22
Nombre = Nombre * 2
If (Nombre >= 1) Then
bit(22 - i) = 1
Nombre = Nombre - 1
End If
Next
End If

'** récupération du nombre codé sous forme de 4 codes ASCII **
Index = 0
For j = 0 To 3
car(j) = 0
For i = 0 To 7
If bit(Index) Then
car(j) = car(j) + (2 ^ i)
End If
Index = Index + 1
Next
Next
End Function

Private Function DécodageIEEE(Car1, Car2, Car3, Car4 As Byte) As Single

Dim signe As Integer
Dim exposant As Integer
Dim Mantisse As Single

If Car1 + Car2 + Car3 + Car4 = 0 Then
DécodageIEEE = 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

DécodageIEEE = ((1 + Mantisse) * 2 ^ (exposant - 127) * signe)

End Function
2
cs_bedu Messages postés 3 Date d'inscription lundi 10 juillet 2006 Statut Membre Dernière intervention 30 novembre 2010
30 nov. 2010 à 12:08
Super.

Merci pour la petite procédure.
C'est ce que je cherchait pour lire les data d'un automate télémécanique.

A+
0
Rejoignez-nous