|
-
Mar 31st, 2001, 12:29 PM
#1
Thread Starter
Fanatic Member
I want to make a program that does this, but I need to know how to do this first. Also, how would you make a loop that goes through a string and converts all the characters?
Alcohol & calculus don't mix.
Never drink & derive.
-
Mar 31st, 2001, 01:17 PM
#2
Monday Morning Lunatic
This to loop through each character in a string:
Code:
void main() {
string sSrc = "Hello World!";
for(int i = 0; i < sSrc.length(); i++) {
string sRes = Convert(sSrc[i]);
cout << sRes << endl;
}
}
string Convert(char cChar) {
// Do what you want to it in this function
char pcBuf[9];
for(int i = 0; i < 8; i++) {
pcBuf[i] = ((cChar >> (8-i)) & 0x1) + '0';
}
pcBuf[9] = 0;
return string(pcBuf);
}
Not totally sure on the binary conversion there (didn't have chance to test it). If the numbers are the wrong way round just change the (8 - i) in Convert.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 5th, 2001, 05:50 PM
#3
Thread Starter
Fanatic Member
Can you please tell me what headers I need to include? I am getting three errors that I can't seem to getr rid of, I will post them it is helps you at all.
Alcohol & calculus don't mix.
Never drink & derive.
-
Apr 5th, 2001, 07:01 PM
#4
Code:
#include <iostream>
#include <string>
using namespace std;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|