Last active
August 29, 2015 13:58
-
-
Save marwein/9955562 to your computer and use it in GitHub Desktop.
Conv Bin To Dec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Program conv; | |
| Uses crt; | |
| Var | |
| nbr : string; | |
| Function Puissance(nombre,puiss : integer) : Qword; | |
| Begin | |
| if (puiss > 0) Then | |
| Puissance := nombre * Puissance(nombre, puiss - 1) | |
| else | |
| Puissance := 1; | |
| End; | |
| Function Conv2a10(nombre : string) : Qword; | |
| Var | |
| i, longueur : integer; | |
| decimal : Qword; | |
| Begin | |
| i := 0; | |
| decimal := 0; | |
| longueur := length(nombre); | |
| While i <= longueur Do | |
| Begin | |
| if nombre[i] = '1' Then | |
| decimal := decimal + Puissance(2, longueur - i); | |
| Inc(i); | |
| end; | |
| Conv2a10 := decimal; | |
| end; | |
| begin | |
| writeln('Saisissez le Code Binaire a convertir SVP : '); | |
| readln(nbr); | |
| write('(',nbr,')2 => (',Conv2a10(nbr),')10'); | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment