begin process at 2012 02 12 11:07:22
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Maths

 > CONVERTISEUR BINAIRE, HEXA, OCTAL ET DECIMAL

CONVERTISEUR BINAIRE, HEXA, OCTAL ET DECIMAL


 Information sur la source

Note :
3,5 / 10 - par 2 personnes
3,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Maths Niveau :Débutant Date de création :27/04/2005 Date de mise à jour :28/04/2005 18:38:40 Vu / téléchargé :6 371 / 378

Auteur : didyman

Ecrire un message privé
Site perso
Commentaire sur cette source (7)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Ce programme date de longtemps mais j'étais tanner de mettre des commentaires sur des sources quand je n'avais meme pas moi même poster une source alors ça va être a mon tour de me faire jugé :P

Je l'ai fait durant mon cour de binaire et hexa a l'école... c'est pour sa qu'il s'apelle Binaire2Hexa mais je l'ai évoluer avec le temps

Je ne connaissais pas la fonction Hex() et les autres s'il y en a alors j'ai tous fait a la main.

Donnez moi des commentaires svp...
Et je suis désoler si je n'ai pas mis de commentaire dans ma source car j'aime pas ben ben sa en mettre!!!  Même si je sais que c'est important.

Source

  • 'Exemple de code dans mon programme
  • Private Sub Bo_Binaire2Hexa_Click()
  • Et_Hexa.Caption = ""
  • Var_Len = Len(Zt_Binaire.Text)
  • Var_OK = Var_Len / 4
  • If Right(Var_OK, 2) = "25" Then Zt_Binaire.Text = "000" + Zt_Binaire.Text
  • If Right(Var_OK, 2) = ",5" Then Zt_Binaire.Text = "00" + Zt_Binaire.Text
  • If Right(Var_OK, 2) = "75" Then Zt_Binaire.Text = "0" + Zt_Binaire.Text
  • Var_Len = Len(Zt_Binaire.Text)
  • Do Until Var_Fois >= (Var_Len / 4)
  • Var_Fois = Var_Fois + 1
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0000" Then Et_Hexa.Caption = Et_Hexa.Caption + "0"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0001" Then Et_Hexa.Caption = Et_Hexa.Caption + "1"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0010" Then Et_Hexa.Caption = Et_Hexa.Caption + "2"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0011" Then Et_Hexa.Caption = Et_Hexa.Caption + "3"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0100" Then Et_Hexa.Caption = Et_Hexa.Caption + "4"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0101" Then Et_Hexa.Caption = Et_Hexa.Caption + "5"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0110" Then Et_Hexa.Caption = Et_Hexa.Caption + "6"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0111" Then Et_Hexa.Caption = Et_Hexa.Caption + "7"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1000" Then Et_Hexa.Caption = Et_Hexa.Caption + "8"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1001" Then Et_Hexa.Caption = Et_Hexa.Caption + "9"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1010" Then Et_Hexa.Caption = Et_Hexa.Caption + "A"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1011" Then Et_Hexa.Caption = Et_Hexa.Caption + "B"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1100" Then Et_Hexa.Caption = Et_Hexa.Caption + "C"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1101" Then Et_Hexa.Caption = Et_Hexa.Caption + "D"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1110" Then Et_Hexa.Caption = Et_Hexa.Caption + "E"
  • If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1111" Then Et_Hexa.Caption = Et_Hexa.Caption + "F"
  • Loop
  • Clipboard.SetText Et_Hexa.Caption 'Met la réponse dans le presse-papier
  • End Sub
  • 'Apres modification :
  • Private Sub Bo_Binaire2Hexa_Click()
  • Et_Hexa.Caption = ""
  • Var_Len = Len(Zt_Binaire.Text)
  • Var_OK = Var_Len / 4
  • Select Case Right(Var_OK, 2)
  • Case "25"
  • Zt_Binaire.Text = "000" + Zt_Binaire.Text
  • Case ",5"
  • Zt_Binaire.Text = "00" + Zt_Binaire.Text
  • Case "75"
  • Zt_Binaire.Text = "0" + Zt_Binaire.Text
  • End Select
  • Var_Len = Len(Zt_Binaire.Text)
  • Do Until Var_Fois >= (Var_Len / 4)
  • Var_Fois = Var_Fois + 1
  • Select Case Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4)
  • Case "0000"
  • Et_Hexa.Caption = Et_Hexa.Caption + "0"
  • Case "0001"
  • Et_Hexa.Caption = Et_Hexa.Caption + "1"
  • Case "0010"
  • Et_Hexa.Caption = Et_Hexa.Caption + "2"
  • Case "0011"
  • Et_Hexa.Caption = Et_Hexa.Caption + "3"
  • Case "0100"
  • Et_Hexa.Caption = Et_Hexa.Caption + "4"
  • Case "0101"
  • Et_Hexa.Caption = Et_Hexa.Caption + "5"
  • Case "0110"
  • Et_Hexa.Caption = Et_Hexa.Caption + "6"
  • Case "0111"
  • Et_Hexa.Caption = Et_Hexa.Caption + "7"
  • Case "1000"
  • Et_Hexa.Caption = Et_Hexa.Caption + "8"
  • Case "1001"
  • Et_Hexa.Caption = Et_Hexa.Caption + "9"
  • Case "1010"
  • Et_Hexa.Caption = Et_Hexa.Caption + "A"
  • Case "1011"
  • Et_Hexa.Caption = Et_Hexa.Caption + "B"
  • Case "1100"
  • Et_Hexa.Caption = Et_Hexa.Caption + "C"
  • Case "1101"
  • Et_Hexa.Caption = Et_Hexa.Caption + "D"
  • Case "1110"
  • Et_Hexa.Caption = Et_Hexa.Caption + "E"
  • Case "1111"
  • Et_Hexa.Caption = Et_Hexa.Caption + "F"
  • End Select
  • Loop
  • Clipboard.SetText Et_Hexa.Caption
  • End Sub
'Exemple de code dans mon programme

Private Sub Bo_Binaire2Hexa_Click()
    Et_Hexa.Caption = ""
    Var_Len = Len(Zt_Binaire.Text)
    Var_OK = Var_Len / 4
    If Right(Var_OK, 2) = "25" Then Zt_Binaire.Text = "000" + Zt_Binaire.Text
    If Right(Var_OK, 2) = ",5" Then Zt_Binaire.Text = "00" + Zt_Binaire.Text
    If Right(Var_OK, 2) = "75" Then Zt_Binaire.Text = "0" + Zt_Binaire.Text
    Var_Len = Len(Zt_Binaire.Text)
    Do Until Var_Fois >= (Var_Len / 4)
        Var_Fois = Var_Fois + 1
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0000" Then Et_Hexa.Caption = Et_Hexa.Caption + "0"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0001" Then Et_Hexa.Caption = Et_Hexa.Caption + "1"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0010" Then Et_Hexa.Caption = Et_Hexa.Caption + "2"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0011" Then Et_Hexa.Caption = Et_Hexa.Caption + "3"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0100" Then Et_Hexa.Caption = Et_Hexa.Caption + "4"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0101" Then Et_Hexa.Caption = Et_Hexa.Caption + "5"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0110" Then Et_Hexa.Caption = Et_Hexa.Caption + "6"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "0111" Then Et_Hexa.Caption = Et_Hexa.Caption + "7"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1000" Then Et_Hexa.Caption = Et_Hexa.Caption + "8"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1001" Then Et_Hexa.Caption = Et_Hexa.Caption + "9"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1010" Then Et_Hexa.Caption = Et_Hexa.Caption + "A"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1011" Then Et_Hexa.Caption = Et_Hexa.Caption + "B"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1100" Then Et_Hexa.Caption = Et_Hexa.Caption + "C"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1101" Then Et_Hexa.Caption = Et_Hexa.Caption + "D"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1110" Then Et_Hexa.Caption = Et_Hexa.Caption + "E"
        If Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4) = "1111" Then Et_Hexa.Caption = Et_Hexa.Caption + "F"
    Loop
    Clipboard.SetText Et_Hexa.Caption 'Met la réponse dans le presse-papier
End Sub

'Apres modification :

Private Sub Bo_Binaire2Hexa_Click()
    Et_Hexa.Caption = ""
    Var_Len = Len(Zt_Binaire.Text)
    Var_OK = Var_Len / 4
    Select Case Right(Var_OK, 2)
        Case "25"
            Zt_Binaire.Text = "000" + Zt_Binaire.Text
        Case ",5"
            Zt_Binaire.Text = "00" + Zt_Binaire.Text
        Case "75"
            Zt_Binaire.Text = "0" + Zt_Binaire.Text
    End Select
    Var_Len = Len(Zt_Binaire.Text)
    Do Until Var_Fois >= (Var_Len / 4)
        Var_Fois = Var_Fois + 1
        Select Case Right(Left(Zt_Binaire.Text, (Var_Fois * 4)), 4)
            Case "0000"
                Et_Hexa.Caption = Et_Hexa.Caption + "0"
            Case "0001"
                Et_Hexa.Caption = Et_Hexa.Caption + "1"
            Case "0010"
                Et_Hexa.Caption = Et_Hexa.Caption + "2"
            Case "0011"
                Et_Hexa.Caption = Et_Hexa.Caption + "3"
            Case "0100"
                Et_Hexa.Caption = Et_Hexa.Caption + "4"
            Case "0101"
                Et_Hexa.Caption = Et_Hexa.Caption + "5"
            Case "0110"
                Et_Hexa.Caption = Et_Hexa.Caption + "6"
            Case "0111"
                Et_Hexa.Caption = Et_Hexa.Caption + "7"
            Case "1000"
                Et_Hexa.Caption = Et_Hexa.Caption + "8"
            Case "1001"
                Et_Hexa.Caption = Et_Hexa.Caption + "9"
            Case "1010"
                Et_Hexa.Caption = Et_Hexa.Caption + "A"
            Case "1011"
                Et_Hexa.Caption = Et_Hexa.Caption + "B"
            Case "1100"
                Et_Hexa.Caption = Et_Hexa.Caption + "C"
            Case "1101"
                Et_Hexa.Caption = Et_Hexa.Caption + "D"
            Case "1110"
                Et_Hexa.Caption = Et_Hexa.Caption + "E"
            Case "1111"
                Et_Hexa.Caption = Et_Hexa.Caption + "F"
        End Select
    Loop
    Clipboard.SetText Et_Hexa.Caption
End Sub



 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

27 avril 2005 23:29:25 :
faute d'orthographe
28 avril 2005 18:38:40 :
Amélioration du code (Changer les IF pour des Select Case (Merci ticomic) , nouveau screenshot

 Sources du même auteur

Source avec Zip Source avec une capture OUVRIR ET FERMER LE CD-ROM A DISTANCE

 Sources de la même categorie

Source avec Zip Source avec une capture CONVERTISSEUR HEXAVIGÉSIMAL par shaeks
Source avec Zip Source avec une capture Source .NET (Dotnet) CRYPTOGRAPHIE AFFINE par Tigrou66
Source avec Zip Source avec une capture SCANNER FLEX par lajouad
Source avec Zip EQUATIONSECONDDEGRÉ,MATH,DEGRÉ par shadkitenge
Source avec Zip Source .NET (Dotnet) SOMME DE CHIFFRES CONTENUE DANS UN NOMBRE par alpha5

Commentaires et avis

Commentaire de jessoulabrute le 28/04/2005 02:05:50

Je sais pas si tu sais, mais ya déjà plusieurs codes de ce genre sur le site, disont que ca devient redondant si les sources n'ont rien de spécial.

Deuxièmement, je peux tout de suite voir que tu aurait pu utiliser end select au lieux de tous ces ifs (le processus en serait accéléré théoriquement).

De plus, tu te sert du clipboard?? Pas fort, ça, tu aurait en premier lieu du te servir d'une fonction, qui peux retourner un type ce qui est son utilité comparée a un sub, et puis au moins si tu utilise un sub, tu aurait pu mettre la valeur dans une variable au lieu que l'utilisateur aurait alors pu utiliser.

Encore une chose, Bo_Binaire2Hexa_Click() ne prend aucun argument!  bon, une fonction aurait été mieux comme je disais, mais sinon tu aurait pu faire:
sub Bo_Binaire2Hexa_Click(byval nombrebinaire as string)

Bon, en tk, je te suggère d'aller voir les autres sources qui font la même chose (mais mieux) sur vbfrance je crois qu'il y en a a peu près 10 sinon plus.

Vraiment, c'est à améliorer.

Commentaire de ticomic le 28/04/2005 02:07:03

Désolé, c'est moi qui a posté tout ca, pas Jesslabrute (auto login oups)

Commentaire de didyman le 28/04/2005 02:20:00

Se code date de ya 2 ans et je ne connaisssais pas Select Case dans se temps la....

Mais c'est vrai que j'aurais pu l'adapter a se que je connais aujourd'hui avant de le poster...

et en passant Bo_Binaire2Hexa_Click() est un bouton alors impossible de mettre une variable! (messenble... logiquement)

Merci pour tes commentaire, j'en prend note!

Commentaire de NHenry le 28/04/2005 09:54:33 administrateur CS

Ton code de conversion en hexa et vraiment lourd, tu peut t'y prendre par un calcul.

Commentaire de Tukkkko le 28/04/2005 12:42:55

Ce code n'est pas terrible, ceci dit, MERCI DE BIEN VOULOIR ECRIRE FRANCAIS, ça ne serait pas mal du tout

Commentaire de didyman le 28/04/2005 13:06:59

je ne comprend pas... j'écris français???  jme suis même forcer sur mes faute d'orthographe!!!

Merci pour vos commentaires!

Je vais tous le recorriger aujourd'hui... changer les IF par des Select Case et ajouter des commentaires.

Commentaire de ticomic le 29/04/2005 22:31:20

Eum, pour le français je comprend pas trop, je le trouve correcte, surtout qu'il n'y a pas beaucoup de mots la-dedans.

Mais ce que je voulais dire c'est plutot de faire une fonction au lieu d'un boutton. Bon, je donne un exemple plus clair:

Private Function Binaire2Hexa (byval nombrebinaire as string)
Ici ya tout le code pour convertir
Binaire2hexa = Nombre hexadécimal
End function

De cette façon, tu n'as qu'a mettre ca dans le boutton:
(ok, disons que tu le fais avec un msgbox par exemple)
msgbox "Le nombre hexadécimal est:" & Binaire2hexa(Zt_Binaire.Text)

C'est la particularité des fonctions, elle peuvent retourner une valeur et donc être utilisées presque comme des variables.  Cela sert aussi de manière à ce que tu puisse mettre la fonction disons dans un module ou une dll (ca je ne connais pas ca, mais je crois que c'est possible).  Comme ça tu peux convertir un nombre sans faire call bo_binaire2hexa_click et tu peux convertir un nombre qui n'est pas nécéssairement dans un endroit précis (tu n'as besoin que de la variable), et je répete que ça évite d'enlever ce qu'il y a déjà dans le clipboard.  Bon, voila à peu près ce que devrais avoir l'air ton code (bon, c'est juste mon avis quand même, mais je crois que les autres membres seront d'accord):

Private Function Binaire2Hexa(ByVal nombre As String) As String
Dim nombrehexa As String
    nombrehexa = ""
    Var_Len = Len(nombre)
    Var_OK = Var_Len / 4
    Select Case Right(Var_OK, 2)
        Case "25"
            nombre = "000" + nombre
       Case ",5"
            nombre = "00" + nombre
        Case "75"
            nombre = "0" + nombre
    End Select
    Do Until Var_Fois >= (Var_Len / 4)
        Var_Fois = Var_Fois + 1
        Select Case Right(Left(nombre, (Var_Fois * 4)), 4)
            Case "0000"
                nombrehexa = nombrehexa + "0"
            Case "0001"
                nombrehexa = nombrehexa + "1"
            Case "0010"
                nombrehexa = nombrehexa + "2"
            Case "0011"
                nombrehexa = nombrehexa + "3"
            Case "0100"
                nombrehexa = nombrehexa + "4"
            Case "0101"
                nombrehexa = nombrehexa + "5"
            Case "0110"
                nombrehexa = nombrehexa + "6"
            Case "0111"
                nombrehexa = nombrehexa + "7"
            Case "1000"
                nombrehexa = nombrehexa + "8"
            Case "1001"
                nombrehexa = nombrehexa + "9"
            Case "1010"
                nombrehexa = nombrehexa + "A"
            Case "1011"
                nombrehexa = nombrehexa + "B"
            Case "1100"
                nombrehexa = nombrehexa + "C"
            Case "1101"
                nombrehexa = nombrehexa + "D"
            Case "1110"
                nombrehexa = nombrehexa + "E"
            Case "1111"
                nombrehexa = nombrehexa + "F"
        End Select
    Loop
Binaire2Hexa = nombrehexa
End Function

Et pour transformer un nombre binaire tu fais tout simplement nombrehexa = Binaire2hexa(nombrebinaire)

Bonne prog!

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,764 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales