Hi All,
Please advice for SV casting;
- static_type_conversion;
int a;
real b;
initial begin
//real to int
a = int ' (3.14); //line1
$display("1 INT = %0d", a);
a = 3.14; //line2
$display("2 INT = %0d", a);
end
////////output
1 INT = 3
2 INT = 3
with casting, we will get output 3. But we are getting same result also with line2, that is without casting, due to implicit conversion. Then for what purpose are we using type (one type to another data type) conversion ?
- static_size_conversion;
int unsigned num;
logic [7:0] a;
initial begin
a = 8'(num); // Reduce integer (32bit) to 8bit
num = 16'd300;
$display("3 INT = %0d", num);
end
////output
3 INT = 300
Here, I converted num from 16bit to 8 bit, 2^8=256, it means it should have only maximum of 255. But how come, num is taking more than 8bit value, size conversion is unsuccessful … ?
Could anyone suggest casting for size and type conversion with example usage ?
Thank You,
Mahesh