| |
 | Contributor Rep Power: 3 Reputation: 154
  | | Posts: 1,242 Join Date: Mar 2007 Location: /b/ | |
| Text-to-Binary :P -
01-21-2008
This is a simple text-to-binary thing written in C++ that I thought I'd share since it is useless 
10001011010011101110110000111100101111001100000101010011101001101111111100101101 0011100001110111001 Code: #include <iostream>
using namespace std;
#include <cstring>
#include <cstdlib>
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 to binary stuff (up to 500 chars): ";
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<<endl<<"Do it again?(1 = yes, 2= no)?: ";
cin.getline(choice,3);
if(choice[0] == '1')
prog();
else
exit(0);
}
Save as a ____.cpp file and then compile.
Credits-www.cplusplus.com made most of the code, i edited it around. "I don't fail at stuff, I succeed at finding what doesn't work" |
 |