#include<iostream.h>
#include<cstring.h>
#include<stdio.h>
#include<conio.h>
char *entry, letter, choice[2];
int ascii, len, binary[8], total;
void prog();
int main()
{
prog();
return 0;
}
void prog()
{
entry = new char[501];
cout<<"Enter string to convert Binary (up to 500 chars): ";
gets(entry); //cin.getline(entry, 500);
len = strlen(entry);
for(int i=0;i<len;i++)
{
total=0;
letter=entry[i];
ascii=letter;
while(ascii>0)
{
if((ascii%2)==0)
{
binary[total]=0;
ascii=ascii/2;
total++;
}
else
{
binary[total]=1;
ascii=ascii/2;
total++;
}
}
total--;
while(total>=0)
{
cout<<binary[total];
total--;
}
}
delete[]entry;
cout<<"\n'Di baca dari sebelah kanan, 2 biner terakhir tidak di baca'"<<endl;
cout<<endl<<"\nDo again ? (1=yes, 2=no) = ";
cin.getline(choice,3);
if(choice[0]=='1')
{ clrscr();
prog();
}
else
exit (0);
}
No comments:
Post a Comment