Program biner ke desimal

Ini adalah program untuk mengkonversi bilangan biner menjadi bilangan desimal, maaf  keterbatasan. Sebab program ini hanya dapat mengkonversi minimal 8 digit bilangan biner saja. Selamat mencoba!!!

#include <iostream.h>
#include <conio.h>

char keyboard;
int biner[8],k=0,desimal=2;
void main()
{
clrscr();
cout<<“Masukkan Nilai Biner : “;
while(k<8)
{
keyboard=getch();
if(keyboard==’1′)
{
biner[k]=1;
cout<<biner[k];
k++;
}
else if(keyboard==’0′)
{
biner[k]=0;
cout<<biner[k];
k++;
}
}

cout<<“\nNilai dalam Desimal : “;
k–;

while(k>0)
{
k–;
biner[k]*=desimal;
biner[k]+=biner[k+1];
desimal*=2;
}
desimal=biner[k];
cout<<desimal;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s