Differenze tra le versioni di "Convertire un numero da rappresentazione binaria in decimale"
Da Gambas-it.org - Wikipedia.
(Nuova pagina: Per convertire un numero, espresso in formato a rappresentazione binaria, nella corrispondente rappresentazione ''decimale'', potremo utilizzare questo algoritmo: |1| '''Pu...) |
|||
Riga 24: | Riga 24: | ||
'''End''' | '''End''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | =Note= | |
− | |||
− | |||
[1] Il presente algoritmo è stato suggerito dall'utente ''Picavbg'' del forum di Gambas-it.org. | [1] Il presente algoritmo è stato suggerito dall'utente ''Picavbg'' del forum di Gambas-it.org. |
Versione delle 03:06, 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 b, e As Integer Dim a As String Dim 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.