Differenze tra le versioni di "Convertire un numero da rappresentazione binaria in decimale"
Da Gambas-it.org - Wikipedia.
Riga 2: | Riga 2: | ||
'''Public''' Sub Button1_Click() | '''Public''' Sub Button1_Click() | ||
− | |||
Dim a As String | Dim a As String | ||
− | Dim Intero, InteroFinale As Integer | + | Dim b, Intero, InteroFinale As Integer |
Dim Esponente, crt As Integer | Dim Esponente, crt As Integer | ||
Versione delle 03:08, 16 ago 2013
Per convertire un numero, espresso in formato a rappresentazione binaria, nella corrispondente rappresentazione decimale, potremo utilizzare questo algoritmo: |1|
Public Sub Button1_Click() Dim a As String Dim b, Intero, InteroFinale As Integer Dim Esponente, crt As Integer a = InputBox("Immetti un numero in formato binario:") Esponente = 0 For b = Len(a) To 1 Step -1 crt = Int(Val(Mid(a, b, 1))) Intero = crt * 2 ^ Esponente Esponente += 1 InteroFinale = InteroFinale + Intero Next Print InteroFinale End
Note
[1] Il presente algoritmo è stato suggerito dall'utente Picavbg del forum di Gambas-it.org.