How to Perform Logical operation
-
Hello In my application, i want to perform some logical operation.Ie "AND" operation, "OR"operation,"Exor" operation.. For example.. Enter value1 :-1011 Enter value2 :-1100. Answer is AND :- 1000 OR :- 1111 EXOR :- 0111 Any idea how can i get it..I am trying to Enter binary value as a string but then how to convert string to binary... Please help me..Any new logic ?? Thanks Shah Shah
-
Hello In my application, i want to perform some logical operation.Ie "AND" operation, "OR"operation,"Exor" operation.. For example.. Enter value1 :-1011 Enter value2 :-1100. Answer is AND :- 1000 OR :- 1111 EXOR :- 0111 Any idea how can i get it..I am trying to Enter binary value as a string but then how to convert string to binary... Please help me..Any new logic ?? Thanks Shah Shah
Shah Satish wrote:
..I am trying to Enter binary value as a string but then how to convert string to binary...
Assuming you need to do that, use atoi to convert.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hello In my application, i want to perform some logical operation.Ie "AND" operation, "OR"operation,"Exor" operation.. For example.. Enter value1 :-1011 Enter value2 :-1100. Answer is AND :- 1000 OR :- 1111 EXOR :- 0111 Any idea how can i get it..I am trying to Enter binary value as a string but then how to convert string to binary... Please help me..Any new logic ?? Thanks Shah Shah
Shah Satish wrote:
how to convert string to binary...
Take a look at strtol[^]. You can provide 2 as the basis and it will convert your string representing a binary into a long. Then you just perform logical operations on your long (&& for AND, || for OR, for XOR I don't remember what it was but you can make an OR and then invert the result with !).
Cédric Moonen Software developer
Charting control [v1.2] -
Shah Satish wrote:
..I am trying to Enter binary value as a string but then how to convert string to binary...
Assuming you need to do that, use atoi to convert.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Christian Graus wrote:
use atoi to convert.
In that case, the string need to be in decimal representation, not in binary representation.
Cédric Moonen Software developer
Charting control [v1.2] -
Shah Satish wrote:
how to convert string to binary...
Take a look at strtol[^]. You can provide 2 as the basis and it will convert your string representing a binary into a long. Then you just perform logical operations on your long (&& for AND, || for OR, for XOR I don't remember what it was but you can make an OR and then invert the result with !).
Cédric Moonen Software developer
Charting control [v1.2]Thank you dear..I got my solution.
-
Hello In my application, i want to perform some logical operation.Ie "AND" operation, "OR"operation,"Exor" operation.. For example.. Enter value1 :-1011 Enter value2 :-1100. Answer is AND :- 1000 OR :- 1111 EXOR :- 0111 Any idea how can i get it..I am trying to Enter binary value as a string but then how to convert string to binary... Please help me..Any new logic ?? Thanks Shah Shah
Hi Shah, Following routine should do the job: int StrToBinary (LPCTSTR szString) { int nBit = 1; int nResult = 0; int i; i = strlen (szString); while (i > 0) { if (szString[--i] != '0') nResult |= nBit; nBit *= 2; } return nResult; } Good luck William
-
Hi Shah, Following routine should do the job: int StrToBinary (LPCTSTR szString) { int nBit = 1; int nResult = 0; int i; i = strlen (szString); while (i > 0) { if (szString[--i] != '0') nResult |= nBit; nBit *= 2; } return nResult; } Good luck William
Hi Wim..Thanks for your reply..