1
0
Fork 0
mirror of https://codeberg.org/DansLeRuSH/c-plus-plus-exercises.git synced 2024-05-18 08:14:57 +00:00

Convert a binary number (1 byte) to decimal

This commit is contained in:
Franck ALBARET 2018-10-22 07:31:02 +00:00
parent 406f5787a1
commit 815f75897d

View 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;
}