Learning BSV‎ > ‎Data Types‎ > ‎

Int#(n)

The Int#(n) type is a signed fixed width representation of an integer value, where n indicates the number of bits.

 Int#(n)

Usage

  • Defines a signed (two's-complement) integer of width ''n''. 
  • Used to represent and compare variables which should be interpreted as signed quantities.
  • int is a synonym for Int#(32).
  • Use signExtend to create larger integers by adding zero bits to the MSB of the argument and replicating the sign bit.
  • Use truncate to create smaller integers by removing bits from the MSB of the argument.

Examples


 Int#(8)  a = 'h80;
 Int#(12) b = signExtend(a); // b => 'hF80
 Int#(8)  c = truncate(d);   // c => 'h80

Data Type Conversion Functions

Bluespec provides a set of functions to convert a type between Bit#(n) and other types.  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