• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about this expression "c {1, WIDTHx {1b0}}" how can 2 ^ WIDTH do this?
#1
Hello,
I can't understand how this expression "c {1, WIDTHx {1b0}}" how can 2 ^ WIDTH accomplish this?
It is found in the Decoder component and in the example of the 7-segment display 2 ^ WIDTH = 8, but how is this possible?

Thank you
  Reply
#2
This expression is the equivalent to the C/Java/other programming expression 1<<WIDTH.

When WIDTH is 1, the output will be c{1b1, 1b0} = 2b10 = 2 = 2^1
When WIDTH is 4, the output will be c{1b1, 4b0000} = 5b10000 = 16 = 2^4
  Reply
#3
(11-02-2020, 06:19 PM)alchitry Wrote: This expression is the equivalent to the C/Java/other programming expression 1<<WIDTH.

When WIDTH is 1, the output will be c{1b1, 1b0} = 2b10 = 2 = 2^1
When WIDTH is 4, the output will be c{1b1, 4b0000} = 5b10000 = 16 = 2^4

Thanks,
Now with a little more experience I understand how it works.

In one of my modules, however, I used "the directive" I don't know if it is called so in lucid "$pow(2, WIDTH)" which seems more intuitive to me, I don't think it introduces errors in particular cases?
  Reply
#4
I believe the $pow() function didn't exist when I wrote the 7-seg example which is why I did it the bit-wise way. I'd definitely recommend the $pow() function over the bit-wise method for clarity now. They both are only good for constants and should be interchangeable.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)