quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - casting
   

space.gif


  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
   

space.gif

  ../images/main/bullet_star_pink.gif Simulator Output
   

space.gif

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

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com