Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between single (&) and double (&&) ampersand binary operators?

In IEEE 1800-2005 or later, what is the difference between & and && binary operators? Are they equivalent?

I noticed that these coverpoint definitions behave identically where a and b are of type bit:

  • cp: coverpoint a & b;
  • cp: coverpoint a && b;
like image 952
Victor Lyuboslavsky Avatar asked Jun 26 '13 18:06

Victor Lyuboslavsky


People also ask

Which is best single or relationship?

It is true that being single is better than being in a bad relationship or a bad marriage. It is demonstrably true — research shows that. Actually, research shows more than that. Being single is even better than being in a romantic relationship that isn't particularly bad.

Does single mean not dating?

In common usage, the term 'single' is often used to refer to someone who is not involved in any type of romantic relationship, including long-term dating, engagement, marriage, or someone who is 'single by choice'. Single people may participate in dating and other activities to find a long-term partner or spouse.

What is the difference between single and single?

There are some differences between being Single and Unmarried. Most unmarried people consider themselves single. Unmarried means being without a spouse or it is one who is legally divorce. But the meaning of a single is different, like a unique, different, and independent person.

What is difference between unmarried and single?

A Single Man/Woman: A man or woman who has not been legally married. For example: John Buyer, a single man. An Unmarried Man/Woman: A man or woman who was previously married and is now legally divorced. For example: Jill Seller, an unmarried woman.


2 Answers

&& is a boolean operator which we call "logical AND". This doesn't mean that it must operate on boolean operands, but that its return type is boolean. In SV, boolean means:

1'b1 \\ true
1'b0 \\ false
1'bx \\ undef

When logical AND operates on single bit operands the result is obvious, but the issue arises when it operates on a vector. For example:

logic [1:0] vector;
...
vector = 2'b10;
if (1'b1 && vector) ...

For purpose of this logical operation, vector is tested for equality to 0. If it is, then its boolean value is defined as "false", otherwise "true". In the above example, the result is "true".

& is a bitwise AND and reduction AND operators. Whether it is executed as bitwise or reduction is determined by the context:

logic [1:0] vector1;
logic [1:0] vector2;
logic [1:0] vector3;
...
vector1 = 2'b10;
vector2 = 2'b01;
...
vector3 = vector2 & vector1; // bitwise; vector3 = 2'b00
if ( (&vector1) || (&vector2) ) ... // reduction; the result of each reduction is 1'b0

Bitwise operator performs logical AND operation on each pair of corresponding bits of operands. The result is a vector which width equals to maximal width of operands.

Reduction operator performs logical AND operation between all the bits of a single vector. The result is a single bit boolean value.

NOTE: when executed on a single bit operands, the results of bitwise and logical operators are the same. However, when even one of the operands is a vector, the results may differ.

like image 63
Vasiliy Avatar answered Nov 07 '22 13:11

Vasiliy


&& is logical AND. It accepts two booleans and returns boolean.

& is bitwise AND. It accepts two numbers and returns a number.

In the above example, the behavior would be different if a and b where both packed bit [1:0].

like image 24
Victor Lyuboslavsky Avatar answered Nov 07 '22 12:11

Victor Lyuboslavsky