Learning BSV‎ > ‎Data Types‎ > ‎

UInt#(n)

The UInt type is an unsigned fixed width representation of an integer value where n indicates the number of bits.

 UInt#(n)

Usage

  • Defines an unsigned integer of n bits in width.
  • Used to represent and compare variables which should be interpreted as unsigned quantities.  
  • Unsigned variables are always greater than or equal to zero.
  • Use zeroExtend to create larger integers by adding zero bits to the MSB of the argument.
  • Use truncate to create smaller integers by removing bits from the MSB of the argument.

Examples


 UInt#(8)  a = 'h80;
 UInt#(12) b = zeroExtend(a); // b => 'h080
 UInt#(8)  c = truncate(b);   // c => 'h80


Data Type Conversion Functions

Bluespec provides a set of functions to convert a type between Bool and another type.  During type checking, the compiler resolves these functions to a particular type instance. If you have excessive type conversion in your design, it usually indicates a poor choice of the basic object types in the design, and you may want to review your type choices.  These conversion utilities do not incur logic overhead.
Comments