Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

logical AND vs Bitwise AND

Status
Not open for further replies.

rockgird

Junior Member level 3
Junior Member level 3
Joined
Apr 28, 2006
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,543
hello,

As per synthesis/fabrication point of view, which among logical AND/OR (&&/||) or Bitwise AND/OR (&/|) is better ... given that operation is being performed of single bit stream of data.
 

The difference can be very miserable.
In my opinion bit wise should be better. Because it's close to the real hardware more then logical.

Bests,
Tiksan
 

actually one of the senior member in my company use logical or/and instead of bitwise, I prefer bitwise so i wanted to know first the complications with the former before i go and talk to him about it :)
 

The conflict should be solved by company coding style :D
 

On the basis of output both(&& with &) are same.

A B && &
-----------
0 0 0 0
0 1 0 0
1 0 0 0
1 1 1 1

suppose
e1 (&& or &) e2
if we use bitwise & operator then it will evaluate both e1 and e2 after that it will apply & operator.
but using the logical && operator if e1 evaluate false it will no evaluate e2 again it will return false directly. Only the true condition of e1 it will evaluate e2.
Suppose any exception occurred in e2(e2=1/0) and e1 return false.
In this scenario
if we apply bitwise & operator then it will throw exception since the second part also be evaluated.
for the logical && operation it will be execute fine.
 
This was the exact kind of explanation I was looking for ... thank for the help ...

On the basis of output both(&& with &) are same.

A B && &
-----------
0 0 0 0
0 1 0 0
1 0 0 0
1 1 1 1

suppose
e1 (&& or &) e2
if we use bitwise & operator then it will evaluate both e1 and e2 after that it will apply & operator.
but using the logical && operator if e1 evaluate false it will no evaluate e2 again it will return false directly. Only the true condition of e1 it will evaluate e2.
Suppose any exception occurred in e2(e2=1/0) and e1 return false.
In this scenario
if we apply bitwise & operator then it will throw exception since the second part also be evaluated.
for the logical && operation it will be execute fine.
 

If you are operating on 2 bits at a time then there should be no difference between logical and bit wise operations. If you are operating on a number of bits at a time then there is a significant difference. Logical and OR treat each value as zero if all bits are zero and one otherwise then it preforms the logical operation. Bitwise operations will do this on the individual bits.
 
Hi ConradATPG

can you please clear this part with an example.
Logical and OR treat each value as zero if all bits are zero and one otherwise then it preforms the logical operation.

Oterwise what I have understand I am explaning with an example.

boolean m=(0/1) (&/&&) (0/1); its right on programming prospect.
but suppose
int i=3,j=5;
int k=i&j; it is right but here you cannot apply the logical operator(&&).

thats u want to say that bitwise operation apply on indivisual bit where logical && operator operation on 2 bits only???
 

Logical AND:
2'b10 && 2'b01 = 1 (BOOLEAN:TRUE)
2'b10 && 2'b00 = 0 (BOOLEAN:FALSE)

Bitwise AND:
2'b10 & 2'b01 = 2'b00
2'b10 & 2'b00 = 2'b00
 
Last edited:
I assume, that you're talking about C programming. Curiously, the language hasn't be mentioned yet, the original post is most likely rather reffering to Verilog.

int k=i&j; it is right but here you cannot apply the logical operator(&&).
In C language, int k=i&&j; is well defined according to implicite type conversion rules.
It's just the same as this more verbose expression
Code:
k = ((i != 0) && (j != 0))?1:0;
As already mentioned, the original question "which is better" is basically useless.

P.S.: I see, that chipmonkey has shown a similar result of logical and with Verilog.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top