After declaring arbitrary precision variables, now the question is: What are the rules of assigning 1
values to these variables? 2
This lecture will answer this question. 3
Variable initialisation and assignment are possible because of the class constructors and overloaded 4
assignment operators. 5
However, the method of initialisation is subject to the limitations of C++ which can represent numbers 6
up to 64 bits. 7
To allow assignment of values wider than 64-bits, constructors are provided that allow initialisation 8
from a string of arbitrary length. 9
The constructor gets two arguments: a string representing the value and a radix. 10
The radix can be 2, 8, 10, or 16. If it is not defined, the string provided is represented 11
as a hexadecimal value as long as it contains only valid hexadecimal digits 12
(that is, 0-9 and a-f). 13
The constructor can also infer the radix of the number in the string if it is prefixed with a zero (0) 14
followed by one of the following characters: “b”, “o” or “x”. The prefixes “0b”, “0o” and “0x” correspond 15
to binary, octal and hexadecimal formats respectively. 16
These examples show four different ways of initialising a 41-bit variable with an octal number. 17
In C/C++, when we initialise a value by putting ‘0’ before a number, the number is treated as 18
octal. 19
These examples show three different ways of initialising a 763-bit variable with a hexadecimal 20
number. 21
The arbitrary precision integer value can be printed on the screen in a test bench file using 22
std::cout C++ class or printf C function. 23
The C++ modifiers std::oct, std::dec, std::hex can be used to format the printed value. 24
Let’s have a look at the arbitrary precision data type initialisation in action. For this purpose, I 25
have created an HLS project containing four files. 26
The design header file includes the arbitrary precision header file. 27
The design source file contains the top-function which assigns seven constant values to its seven output 28
variables. 29
The testbench header file includes the design header file and consists of the design function prototype. 30
The testbench source file contains the main function that declares seven variables and sends them to 31
the design function for assigning values and finally prints them on the screen. 32
If we perform the C simulation, then the output shows the values assigned to the variables in the design 33
file. 34
These are the values that we have expected. 35
After declaring and initialising bit-accurate variables, we should study the rules of assigning variables 36
together. 37
The next lecture addresses this challenge. 38
These are our takeaway messages. We can use the C/C++ initialisation to assign a value to a declared 39
variable with length less than 64 bits. For arbitrary precision data types, more than 64 bits 40
class constructors can be used for initialisation 41
Now the quiz question. Declare a 362-bit width variable of unsigned integer type and initialise that 42
with a value that set all bits to one.