P
Paul
Paul said:Pete Becker said:On 2011-03-08 16:46:37 -0500, Paul said:
On 2011-03-07 17:48:08 -0500, James Kanze said:
On 2011-03-07 16:53:50 -0500, crea said:
[...]
No, it just needs to a text string that represents the integer
value in
binary. Read about strtoul.
And one that will output the integer value in binary as well.
That's a little harder.
Urk. strtoul goes the wrong way, of course.
#include <iostream>
const int STR_LEN=8;
typedef char bin_str[STR_LEN];
int main()
{
bin_str str1 = "1100110";
bin_str str2 = "1000011";
bin_str str3 = "0000000";
for(int x=0; x<STR_LEN; x++){
if(str1[x]=='1' && str1[x]==str2[x])
str3[x]=str1[x];
}
std::cout<< str3;
}
Shrug. The discussion was about doing this with integer values. It's
already been stated several times that doing it character by character
is better.
No it might actually be more efficient doing it with integer values ,
example:
Since you've snipped all relevant context, there is no meaningful way to
reply to your irrelevant example.
const int STR_LEN=8;
typedef unsigned char bin_str[STR_LEN];
int main()
{
bin_str str1 = "1100110";
bin_str str2 = "1000011";
bin_str str3 = "0000000";
for(int i=0; i<STR_LEN; i++){
str3 = str1& str2;
}
}
The best solution might be to overload the operator& in a specific
string class.
Sure. But that's not what this subthread was about, so please stop
pretending that you've had some insight that's actually useful.
I didn't snip anything.
And I wasn't pretending to have any insight to something usefull , I was
showing you lot how to properly do what you all seemed to be bickering
about.