rnsr
asked on
difference between conditional and logical operators in c#
Need help with example to explain
difference between conditional and logical operators in c#[ &,&&,|,||)
difference between conditional and logical operators in c#[ &,&&,|,||)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I must be sleepy : )
My last example above, "Bitwise AND" should have been "Bitwise OR" and the example code was incorrect as well. It is corrected below.
Bitwise OR
My last example above, "Bitwise AND" should have been "Bitwise OR" and the example code was incorrect as well. It is corrected below.
Bitwise OR
bool iHaveMoney = true;
bool iHaveAFriendWithMoney = true;
if (iHaveMoney || iHaveAFriendWithMoney)
{
// Either are true, so I can buy that new CD
}
else
{
// Both were false, so I going to have to read a book instead.
}
ASKER
Bitwise represent ON and Off concept. But programatically where can i use it in project.
Bitwise is used where the bits in a variable mean something like uppercase/lowercase or 'flags' for processes. You can use "char & 0x5f" to make a character uppercase (at least in ASCII). On this page http://msdn.microsoft.com/en-us/library/ms684863%28v=vs.85%29.aspx is an example of "Process Creation Flags" for Windows. The constants names are usually used instead of the hex values. To set the flags, you would normally use 'or' like "flagset | CREATE_BREAKAWAY_FROM_JOB" to include '0x01000000' in the value of 'flagset'.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could use bitwise AND to check to see if an int is odd or even. if ((num & 1) == 1) will only be true if the last bit is a 1 which would make it an odd number.
ASKER
i need some time to see it as i am busy for the past one week.
will respond soon.
Thanks,
will respond soon.
Thanks,
ASKER
Nice expalined with example
0000 0000 0000 0000 0000 0000 0000 0100
There are, of course, no spaces in between these values--I added them for visual effect.
Now each of these positions can be either of two values: 1 (on) or 0 (off). If we have some series of related concepts that can either be on or off, then we can exploit this binary feature of our int variable to pack more data into the variable than just a simple number. This is the concept of bit flags. Each bit serves to indicate whether or not some value is on or off.
In my above example, lets say that the right-most index represents the "Compiled" flag, and the 2nd right-most represents the "IgnoreCase" flag. If both were on (and assuming nothing else was), then our int would look like this:
0000 0000 0000 0000 0000 0000 0000 0011
As mentioned previously, we would use a bitwise OR to set these values (as demonstrated above). If we wanted to know whether or not these values had been set, then we would use a bitwise AND.