Hi Guys,
Can you please help me with how I can "AND" two strings of binary numbers and put the result in another string, that is I have the following:
string str1 = "1111";
string str2 = "1010";
string str3 = logical AND of str1 and str2;
cheers
|
Go4Expert Founder
|
![]() |
| 6Jul2010,19:29 | #2 |
|
You have to loop through each character and AND them to create 3rd string.
|
|
Mentor
|
![]() |
| 7Jul2010,13:18 | #3 |
|
Do you mean logical or bitwise? Logically, both inputs are TRUE so the output would also be TRUE, typically represented as -1, i.e. "1111", but the bitwise AND of 1111 and 1010 is 1010.
If bitwise then to avoid characterset issues you should use logic, i.e. Code:
str3[i]=(str1[i]=='1' && str2[i]=='1') ? '1' : '0'; Code:
str3[i]=str1[i] & str2[i]; |
|
Go4Expert Member
|
|
| 7Jul2010,15:15 | #4 |
|
Hi,
Actually, I was trying to say bitwise ANDing. Thank you for your suggestions. They greatly helped me! cheers |
|
Go4Expert Founder
|
![]() |
| 7Jul2010,20:15 | #5 |
|
The pleasure is all mine.
|


