Logic AND between some strings

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.
:)
 
P

Paul

Pete Becker said:
Paul said:
On 2011-03-08 20:34:00 -0500, Paul 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.
:)


Um, you've rather missed the point. Once again: that's not what this
subthread was about. It was a discussion of how to make the integral
approach work, not of how best to solve the original question. So, as I've
said several times, your response is irrelevant. And there's no
"bickering" here, just some attempts to make code that works.

But I showed how to make the integral approach work, how is it irrellevant?
 
P

Paul

Pete Becker said:
Pete Becker said:
On 2011-03-09 15:02:14 -0500, Paul said:


On 2011-03-08 20:34:00 -0500, Paul said:

On 2011-03-08 16:46:37 -0500, Paul said:

On 2011-03-07 17:48:08 -0500, James Kanze said:

On Mar 7, 10:03 pm, Pete Becker <[email protected]>
wrote:
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.
:)

Um, you've rather missed the point. Once again: that's not what this
subthread was about. It was a discussion of how to make the integral
approach work, not of how best to solve the original question. So, as
I've said several times, your response is irrelevant. And there's no
"bickering" here, just some attempts to make code that works.

But I showed how to make the integral approach work, how is it
irrellevant?


Um, because that's not what you did? The integral approach was converting
the text to integral values, doing the logical operation on the values,
and converting the result back to text. Your solution operates directly on
the characters in the text strings; as I've said several times, that
approach is clearly preferable. But it's not the approach under discussion
in this subthread.

--

Also note it is possible to further otpimise as explained here:
http://bmagic.sourceforge.net/bmsse2opt.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top