Skip to content

Bits and Int

In Neo, Bits and Int are the two primary types for representing binary data. Both support bitwise operations and equality, whereas Int also supports mathmatical operations and comparisons.

Declaration

Both Bits and Int require a width to be specified, which determines the number of bits in the type.

neo
logic my_bits(0): Bits(32);
logic my_int(0): Int(32);

Constant Values

To create an Int of a constant value, the syntax is [value]#[width], both of which can be parameterized values. An Int can be used anywhere a Bits is expected, so this syntax also works for assigning to Bits.

neo
logic my_int(0): Int(32) = 42#32;
logic my_bits(0): Bits(32) = 42#32;

Concatenation

Both Bits and Int support concatenation with the ## operator. The left operand is the most significant bits, and the right operand is the least significant bits.

neo
logic my_bits(0): Bits(64) = 32#32 ## 16#32;

Bit Selections

To extract a single bit from a value val, use val{bit}, where bit is a number less than the width of val.

To extract a range of bits, use val{from:to}, where from and to are numbers less than the width of val. The selection is inclusive of both from and to. If to is greater than from, the result will be flipped.

Multiple selections can be made with one select operator, for example val{1, 5:3} will return the concatenation of bit 1 and bits 5-3.