Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Logical And Bitwise AND (http://www.chiefdelphi.com/forums/showthread.php?t=23764)

Dave Flowerday 18-01-2004 01:51

Re: Logical And Bitwise AND
 
Quote:

Originally Posted by SeanCassidy
And if I remember correctly, & can be used to make a reference to a variable or other thing, but doesn't require the pointer syntax. (NOTE: This is out of my C++ Book and I do not have any idea if it does go for C, it might)

There is no concept of references in C - it's an enhancement added by C++.

mtrawls 18-01-2004 12:14

Re: Logical And Bitwise AND
 
Quote:

All I was saying is that the two operands can be used to the same end.
Look at this:

Code:

int a = 5, b = 10;

if (a && b) { /* execute this block of code */ }
if (a &  b) { /* now execute this block of code */ }

You'll note that (a&&b) evaluates to true, because both a and b are non-zero. However, and this is fairly important, (a&b) evaluates to false, because (a&b) is (0101b&1010b) is 0. (And as far as address-of operator, remember that in this context & AND && are binary operators.)

Atheist 18-01-2004 13:33

Re: Logical And Bitwise AND
 
Quote:

Originally Posted by mtrawls
Look at this:

Code:

int a = 5, b = 10;

if (a && b) { /* execute this block of code */ }
if (a &  b) { /* now execute this block of code */ }

You'll note that (a&&b) evaluates to true, because both a and b are non-zero. However, and this is fairly important, (a&b) evaluates to false, because (a&b) is (0101b&1010b) is 0. (And as far as address-of operator, remember that in this context & AND && are binary operators.)

I'm not saying that they are interchangeable, because obviously they are not! However, just as war and diplomacy can be used to the same end, && and & can also.

Dave Flowerday 18-01-2004 15:25

Re: Logical And Bitwise AND
 
Quote:

Originally Posted by Atheist
However, just as war and diplomacy can be used to the same end, && and & can also.

We all understand what you're trying to say. What you're saying is that in one particular case, they happen to give the same answer. However, the manner in which you keep saying it is very misleading and implies that they can be used interchangeably. Please keep in mind that many inexperienced people come here looking for advice. The way you've worded several posts in this thread implies that & and && can be used interchangeably, which isn't true.

Things like this:
Quote:

Bitwise AND can be used for the same purpose as logical AND.
Most people would read this to mean that & and && can be used "for the same purpose" which is not true, at least not in the generic case. On a job, if you use the wrong AND (even if it gives the same result!) you will be told to fix it.

Atheist 18-01-2004 16:10

Re: Logical And Bitwise AND
 
Quote:

Originally Posted by Dave Flowerday
We all understand what you're trying to say. What you're saying is that in one particular case, they happen to give the same answer. However, the manner in which you keep saying it is very misleading and implies that they can be used interchangeably. Please keep in mind that many inexperienced people come here looking for advice. The way you've worded several posts in this thread implies that & and && can be used interchangeably, which isn't true.

Things like this:

Most people would read this to mean that & and && can be used "for the same purpose" which is not true, at least not in the generic case. On a job, if you use the wrong AND (even if it gives the same result!) you will be told to fix it.

And since then I have said that they are not interchangeable about 3 or 4 times.

Unless someone selectively reads only certain parts of certain posts I don't think they will get the wrong idea.

With that said, can we end this argument?

jeremy562 22-01-2004 16:35

Re: Logical And Bitwise AND
 
Quote:

Originally Posted by Atheist
And since then I have said that they are not interchangeable about 3 or 4 times.

Unless someone selectively reads only certain parts of certain posts I don't think they will get the wrong idea.

With that said, can we end this argument?

The specific phrase that is misleading is that they can both be used "to the same end". To me, this phrase implies that they do the same thing, which you agree is not the case. Obviously, it's not worth arguing over because (a) no good can possibly come from it, and (b) everyone is in agreement ANYWAY.

The bottom line is, ALWAYS use && and || for logical comparison, and use & and | for bitwise operations. Don't deviate from this, and you shouldn't run into any problems.


All times are GMT -5. The time now is 19:52.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi