|
|
|

|
|
|
|
|
|

|
|
 |
Casting
|
|
|
As in the C language, type casting is used for converting one type of data type to another type of data type. A data type can be changed by using a cast (') operation. The expression to be cast must be enclosed in parentheses or within concatenation or replication braces and is self-determined. |
|
|

|
|
|
|
|
|

|
|
 |
Example - casting
|
|
|

|
|
|
1 module casting_data();
2
3 int a = 0;
4 shortint b = 0;
5
6 initial begin
7 $monitor ("%g a = %d b = %h", $time, a , b);
8 #1 a = int'(2.3 * 3.3);
9 #1 b = shortint'{8'hDE,8'hAD,8'hBE,8'hEF};
10 #1 $finish;
11 end
12
13 endmodule
You could download file casting_data.sv here
|
|
|

|
|
 |
Simulator Output
|
|
|

|
|
|
0 a = 0 b = 0000
1 a = 8 b = 0000
2 a = 8 b = beef
|
|
|

|
|
|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
Copyright © 1998-2025 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|