Convertion

Résolu
MaxSoldier Messages postés 289 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 février 2009 - 6 juin 2005 à 22:15
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 - 9 juin 2005 à 23:46
Je voudrais savoir comment puis-je convertir une valeur ASCII en
Binaire ( ou Charactère en Binaire ) sans avoir à recopier toute la
table ASCII.

Merci !

-=Ar$£nik=-

6 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
6 juin 2005 à 23:23
Salut
Ma contribution :

Dim strBin As String, Valeur As Long, r As Long
Valeur = Asc("a")
strBin = ""
For r = 0 To 15
If (Valeur And (2 ^ r)) > 0 Then
strBin = "1" & strBin
Else
strBin = "0" & strBin
End If
Next r
Debug.Print strBin

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage. (Socrate)
3
pjcleder Messages postés 183 Date d'inscription jeudi 4 février 2010 Statut Membre Dernière intervention 16 septembre 2011 11
6 juin 2005 à 22:24
PAT


dim str as string


dim n as integer


str = "A"


n = Asc(str)


n récupére la valeur ascii du caractére "A" soit 65

A l'inverse, str = Chr(65) récupére A
0
MaxSoldier Messages postés 289 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 février 2009 2
6 juin 2005 à 22:30
J'ai demandé en binaire, pas en Charactères. ( Soit 01100001 pour "a" par exemple )

-=Ar$£nik=-
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
6 juin 2005 à 22:36
MsgBox Byte2String("A")









Private Function Byte2String(c As String) As String

Dim strhex As String

Dim strbin As String

Dim i As Long

strhex = Hex$(Asc(c))

If Len(strhex) 1 Then strhex "0" & strhex

For i = 1 To 2

Select Case Mid$(strhex, i, 1)

Case "0": strbin = strbin + "0000"

Case "1": strbin = strbin + "0001"

Case "2": strbin = strbin + "0010"

Case "3": strbin = strbin + "0011"

Case "4": strbin = strbin + "0100"

Case "5": strbin = strbin + "0101"

Case "6": strbin = strbin + "0110"

Case "7": strbin = strbin + "0111"

Case "8": strbin = strbin + "1000"

Case "9": strbin = strbin + "1001"

Case "A": strbin = strbin + "1010"

Case "B": strbin = strbin + "1011"

Case "C": strbin = strbin + "1100"

Case "D": strbin = strbin + "1101"

Case "E": strbin = strbin + "1110"

Case "F": strbin = strbin + "1111"

End Select

Next i

Byte2String = strbin

End Function


Daniel
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
MaxSoldier Messages postés 289 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 février 2009 2
7 juin 2005 à 23:22
Génial, sa marche, merci beaucoup !

-=Ar$£nik=-
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
9 juin 2005 à 23:46
Re
Oui, ça marche, sauf que j'ai fait une erreur :
Un code ascii n'est codé que sur 8 bits

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage. (Socrate)
0
Rejoignez-nous