0
\$\begingroup\$

Today I learned about & and ! operators. But I can't understand what is the difference between these two:

  1. A=B & C;

  2. AND(A,B,C);

Do they have exactly the same usage?

Shashank V M
2,36918 silver badges56 bronze badges
asked Dec 2, 2020 at 6:49
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

There are actually different concepts. When you use AND gate it means that you have two ( or more) "one bit" inputs and the output is zero unless all of them are high. On the other hand the operator "&" means bitwise "and". It means that if you have two ,let's say, four bits binary numbers "a" and "b", "a & b" will be also a four bit binary number,in which each bit is the result of and operation on respective bits. For example :

A = 4'b1001
B = 4'b1110
then : 
A & B = 4'b1000

If you want to use & instead of AND gate you have to remember that you have to assign the value to it:

assign out = a & b
above line is equal to:
AND(out,a,b);

Conclusion: as far as we are working with one bit inputs, it doesn't make difference but we have to remember that the concepts are different.

*By the way for the above example if you use &A the result will be 0. It actually ands all of the bits in A. These kind of operators are called Reduction operators. So & operator has two usages:

  1. Reduction operator : ands all of the bits
  2. Bitwise operator : ands the bits of two different input respectively and returns the result.

We can model these two usages with AND gate:

For example A =4'b1010

&A = AND (out,A[0],A[1],A[2],A[3])
answered Dec 2, 2020 at 7:28
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.