如何将 Vec(n,Bool()) 转换为 UInt 值

goa*_*aul 3 scala chisel

作为标题,我想将 Vec(Bool()) 转换为 UInt 值。

例如

class MyModule extends Module {

  val io = IO(new Bundle {
    val in_data    = Input (Vec (3, Bool() ) 
    val result     = Output(UInt(5.W))
  })

  //how can I convert io.in_data to Uint and the assign to io.result
  //I will get io.result = 7 when in_data(1, 1, 1) 
}
Run Code Online (Sandbox Code Playgroud)

Jac*_*nig 6

您可以使用.asUInt将 Vec 转换为 Bools(或任何 Chisel 数据)到 UInt。

如果您需要从 UInt 转换回 Vec 或 Bools,您可以使用 .asBools

请参阅https://www.chisel-lang.org/chisel3/docs/cookbooks/cookbook.html