blob: ca1413dc5c91ca517dfb8b437b0e18608bbc0903 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
// SPDX-License-Identifier: Apache-2.0
package cookbook
import chisel3._
/* ### How do I create a UInt from a Vec of Bool?
*
* Use the builtin function asUInt
*/
class VecOfBool2UInt extends CookbookTester(1) {
// Example
val vec = VecInit(true.B, false.B, true.B, true.B)
val uint = vec.asUInt
printf(p"$uint") // 13
/* Test
*
* (remember leftmost Bool in Vec is low order bit)
*/
assert(0xd.U === uint)
}
class VecOfBool2UIntSpec extends CookbookSpec {
"VecOfBool2UInt" should "work" in {
assertTesterPasses { new VecOfBool2UInt }
}
}
|