Forum Liberty Basic France

Le 13/11/2013 à 21h21

Administrateur

Groupe: Administrateur

Inscrit le: 04/03/2012
Messages: 1968
Et ben ça y est, ArduBock m'ayant mis les boules, j'ai plongé dans le "C".
Et comme j'ai eu besoin de convertir et ben je me suis fait un petit convertisseur.
Que voici:
Code VB :
 
   NOMAINWIN
    WindowWidth=470
    WindowHeight=230
    UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
 
    STATICTEXT #w.u1, "7", 25, 0, 30, 20
    STATICTEXT #w.u2, "6", 75, 0, 30, 20
    STATICTEXT #w.u3, "5", 125, 0, 30, 20
    STATICTEXT #w.u4, "4", 175, 0, 30, 20
    STATICTEXT #w.u5, "3", 225, 0, 30, 20
    STATICTEXT #w.u6, "2", 275, 0, 30, 20
    STATICTEXT #w.u7, "1", 325, 0, 30, 20
    STATICTEXT #w.u8, "0", 375, 0, 30, 20
    STATICTEXT #w.u9, "Bits", 410, 3, 30, 20
    TEXTBOX #w.a8, 10, 20, 40, 25
    TEXTBOX #w.a7, 60, 20, 40, 25
    TEXTBOX #w.a6, 110, 20, 40, 25
    TEXTBOX #w.a5, 160, 20, 40, 25
    TEXTBOX #w.a4, 210, 20, 40, 25
    TEXTBOX #w.a3, 260, 20, 40, 25
    TEXTBOX #w.a2, 310, 20, 40, 25
    TEXTBOX #w.a1, 360, 20, 40, 25
    BUTTON #w.bin, "Calcule", [gobin], UL, 40, 60, 60, 25
    TEXTBOX #w.a9, 160, 60, 60, 25
    STATICTEXT #w.t10, "Binaire > > Décimal", 240, 63, 200, 20
    STATICTEXT #w.u10, "> > > > >", 105, 63, 50, 20
    STATICTEXT #w.u11, "< < < < <", 105, 103, 50, 20
    TEXTBOX #w.b9, 40, 100, 60, 25
    BUTTON #w.dec, "Calcule", [godec], UL, 160, 100, 60, 25
    STATICTEXT #w.t11, "Décimal > > Binaire", 240, 103, 200, 20
    TEXTBOX #w.b8, 10, 140, 40, 25
    TEXTBOX #w.b7, 60, 140, 40, 25
    TEXTBOX #w.b6, 110, 140, 40, 25
    TEXTBOX #w.b5, 160, 140, 40, 25
    TEXTBOX #w.b4, 210, 140, 40, 25
    TEXTBOX #w.b3, 260, 140, 40, 25
    TEXTBOX #w.b2, 310, 140, 40, 25
    TEXTBOX #w.b1, 360, 140, 40, 25
    STATICTEXT #w.t1, "7", 25, 170, 30, 20
    STATICTEXT #w.t2, "6", 75, 170, 30, 20
    STATICTEXT #w.t3, "5", 125, 170, 30, 20
    STATICTEXT #w.t4, "4", 175, 170, 30, 20
    STATICTEXT #w.t5, "3", 225, 170, 30, 20
    STATICTEXT #w.t6, "2", 275, 170, 30, 20
    STATICTEXT #w.t7, "1", 325, 170, 30, 20
    STATICTEXT #w.t8, "0", 375, 170, 30, 20
    STATICTEXT #w.t9, "Bits", 410, 170, 30, 20
    open "Conversion:  Binaire -> Décimal -> Binaire" FOR WINDOW AS #w
     print #w, "trapclose [quit]"  ' Le print est facultatif
    for x= 1 to 9
        hand$ = "#w.a"+word$("1 2 3 4 5 6 7 8 9",x):#hand$, "!font Arial 12 bold":#hand$, "0"
        hand$ = "#w.b"+word$("1 2 3 4 5 6 7 8 9",x):#hand$, "!font Arial 12 bold"
        hand$ = "#w.u"+word$("1 2 3 4 5 6 7 8 9",x):#hand$, "!font Arial 12 bold"
        hand$ = "#w.t"+word$("1 2 3 4 5 6 7 8 9",x):#hand$, "!font Arial 12 bold"
    next x
    #w.u10, "!font Arial 12 bold":#w.u11,"!font Arial 12 bold"
    #w.t10, "!font Arial 12 bold":#w.t11,"!font Arial 12 bold"
  wait
  [gobin] 'ex: 1 1 0 0 1 0 1 1 = 203
    res=0
    for x=1 to 8
       hand$ = "#w.a"+word$("1 2 3 4 5 6 7 8",x)
       #hand$, "!contents? var$": var(x)= val(var$)
       if var (x)<>1 And var(x)<>0 then notice "0 ou 1 Rien d'autre":wait
       bi(x)= 2^(x-1)
       print bi(x);"....";var(x)
       br(x)=bi(x)*var(x)
    next x
    for x=1 to 8
       res= res+br(x)
    next x
   #w.a9, str$(res)
  wait
  [godec]
    #w.b9, "!contents? dec$": dec= val(dec$)
    if dec > 255 then notice " 8 bits => 255 Max"
    for x= 1 to 8
       hand$ = "#w.b"+word$("1 2 3 4 5 6 7 8",x)
       a=dec/2
       if int(a)*2=dec then #hand$, "0"
       if int(a)*2<>dec then #hand$, "1"
       dec=int(a)
    next x
  wait
  [quit]
    CLOSE #w
    END
 
____________________
Roro

   

 |  |

1 Utilisateur en ligne : 0 Administrateur, 0 Modérateur, 0 Membre et 1 Visiteur
Utilisateur en ligne : Aucun membre connecté
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie