data.representation


template <auto OutputWidth, typename T>
inline bool[OutputWidth] binary_to_one_hot(T index) §source

Generate a onehot of the specified width. A onehot is an array of booleans with a single value set to true. Calling with OutputWidth 8 and index 1 returns an array of 8 bools with only bool 1 set to true. Or in binary, 00000010.

template <typename T, auto Count>
inline auto onehot_mux(uint<Count> onehot, T[Count] data) §source

Similar to mux, but takes a onehot rather than an index as the first parameter. Also takes an array rather than a variable number of arguments for the selection list. The least significant bit in the onehot corresponds to index 0 in the data array.

Examples
>>> onehot_mux<uint2, 4>(1, {0, 1, 2, 3});
0

>>> onehot_mux<uint2, 4>(2, {0, 1, 2, 3});
1

>>> onehot_mux<uint2, 4>(4, {0, 1, 2, 3});
2

The onehot must be valid which means it has exactly one bit set. Like mux, onehot_mux requires that Count is a power of two.

template <typename T>
inline T endian_change(T input) §source

Change a value from big endian to little endian, or vice versa. The input type must be of a size that’s a multiple of 8 bits.

Example
>>> endian_change(0x12345678)
0x78563412