diff options
| author | Jim Lawson | 2016-10-24 10:31:26 -0700 |
|---|---|---|
| committer | Jim Lawson | 2016-10-24 10:31:26 -0700 |
| commit | b0b5fd3140186651eb558bd6f4ca51c618deacc9 (patch) | |
| tree | 1393bbb14303af86aeb5e5ed0375f302864b8307 /src/test/scala/cookbook/VecOfBool2UInt.scala | |
| parent | 82625071405672eb4a19363d6f73f359ac28a7f5 (diff) | |
| parent | 5df30b390ae5817c4793c6d4e0c5466d96d241f1 (diff) | |
Merge branch 'master' into tobits-deprecation
Diffstat (limited to 'src/test/scala/cookbook/VecOfBool2UInt.scala')
| -rw-r--r-- | src/test/scala/cookbook/VecOfBool2UInt.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/scala/cookbook/VecOfBool2UInt.scala b/src/test/scala/cookbook/VecOfBool2UInt.scala new file mode 100644 index 00000000..5852120c --- /dev/null +++ b/src/test/scala/cookbook/VecOfBool2UInt.scala @@ -0,0 +1,28 @@ +// See LICENSE for license details. + +package cookbook + +import chisel3._ + +/* ### How do I create a UInt from a Vec of Bool? + * + * Use the builtin function asUInt + */ +class VecOfBool2UInt extends CookbookTester(0) { + // Example + val vec = Vec(Bool(true), Bool(false), Bool(true), Bool(true)) + val uint = vec.asUInt + printf(p"$uint") // 13 + + /* Test + * + * (remember leftmost Bool in Vec is low order bit) + */ + assert(UInt(0xd) === uint) +} + +class VecOfBool2UIntSpec extends CookbookSpec { + "VecOfBool2UInt" should "work" in { + assertTesterPasses { new VecOfBool2UInt } + } +} |
