View Single Post
  #5   Spotlight this post!  
Unread 16-01-2004, 17:38
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
Re: Logical And Bitwise AND

Quote:
Originally Posted by Atheist
Bitwise AND can be used for the same purpose as logical AND. It looks like that is the case here.
Absolutely NOT TRUE. Again as I've said in previous posts, if you do not know what you're talking about, do not pretend that you do and make untrue assertions. It's best to keep quiet and not confuse people who may believe what you post.

The two are only interchangable here because both expressions of the operand are bits. If they weren't both bits you could get different results with the two operators.

Bitwise AND looks at each bit of the two numbers and does a logical AND on the corresponding bits. Bits in the result are 1 if the corresponding bits in the two operands are both 1, else the bits are 0.

Logical AND looks at the whole expression on each side. If both expressions are nonzero then the AND expression evaluates to TRUE (the value 1 in C).

This snippet of code:
Code:
int a = 0x03;
int b = 0x06;
printf("%d %d\n", (a && b), (a & b));
prints:
Code:
1 2
Why? (a && b) evaluates to TRUE because both numbers are nonzero, so we see a 1. (a & b) in binary is (0011 & 1010) and it evaluates to 0010, or 2.