mirror of
https://codeberg.org/DansLeRuSH/c-plus-plus-exercises.git
synced 2024-11-21 11:18:07 +00:00
Convert a binary number (1 byte) to decimal
This commit is contained in:
parent
406f5787a1
commit
815f75897d
1 changed files with 31 additions and 0 deletions
31
EX09_binaire_en_decimale.cpp
Normal file
31
EX09_binaire_en_decimale.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Auteur : ALBARET Franck
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clrscr();
|
||||
int res=0;
|
||||
int puis [9];
|
||||
char bin [9];
|
||||
int x,y;
|
||||
puts ("Entrer une valeur binaire (1 octet) :");
|
||||
gets (bin);
|
||||
puis[1]=1;
|
||||
for (x=2;x<9;x++)
|
||||
{
|
||||
puis[x]=2*puis[x-1];
|
||||
}
|
||||
y=7;
|
||||
for (x=1;x<9;x++)
|
||||
{
|
||||
if (bin[y]=='1')
|
||||
{
|
||||
res=res+puis[x];
|
||||
}
|
||||
y--;
|
||||
}
|
||||
printf("%i",res);
|
||||
getch();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue