2
\$\begingroup\$

Something like this:

a=b?c:d ; would make a=c, if b=1, else a would be made equal to d;

But what would doing the same thing on an array do? Like this:

assign a = (|b[10:8])?8'hff : b[7:0]; // to limit the max value to 255 Does it check each of the 3 bits, 8, 9 & 10?

asked Nov 22, 2013 at 2:27
\$\endgroup\$
1
  • 1
    \$\begingroup\$ That will take the bit wise or of b[10], b[9], and b[8]. If any of those are 1 then you'll get 255 in a. Otherwise you'll get b[7:0]. Is that what you want? \$\endgroup\$ Commented Nov 22, 2013 at 3:11

1 Answer 1

6
\$\begingroup\$

a = ( | b[10:8] ) ? 8'hff : b[7:0];

When | is used as a prefix, it is a reduction operator. That means it operates on all the bits of the vector that follows it. So what's happening here is the bits of the vector b[10:8] are being or'ed together to get a single bit result.

That result is used to choose whether to assign the constant 8'hFF, or the lower 8 bits of b to a.

answered Nov 22, 2013 at 4:05
\$\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.