Skip to content
asicguru.tech@gmail.com
REGISTER LOGIN
AsicGuru Ventures
  • All Courses
  • CONTACT
  • GALLERY
  • HOME
  • Tutorials

0

Verilog Tutorial

17
  • Introduction
  • Lexical Tokens
  • Gate-Level Modelling
  • Data Types
  • Operators
  • Operands
  • Modules
  • Behavioral Modeling
  • Timing Controls
  • Procedures: Always and Initial Blocks
  • Functions
  • Tasks
  • Component Inference
  • Finite State Machines.
  • Compiler Directives
  • System Tasks and Functions
  • Test Benches

System Verilog

23
  • System Verilog Introduction
  • Data Types
  • Type Casting
  • Arrays
  • Associative Arrays
  • Dynamic Arrays
  • Queue
  • Operators
  • Procedural statements and Control flow
  • Classes
  • Inheritance
  • Encapsulation
  • This and Super operator
  • In-Line Constraints
  • Class Constraints
  • Virtual Classes
  • Parameterized Classes
  • Classes Summary
  • Singleton Classes
  • Functional Coverage Introduction
  • Covergroup
  • Tools
  • Books

Scripting

15
  • Introduction
  • Perl Tutorial
  • What is Perl
  • Perl: Syntax And Variable
  • Perl Strings
  • Perl Arrays
  • Perl Associative Arrays
  • If/While Syntax
  • File Input
  • Print Output
  • String Processing with Regular Expressions
  • Subroutines
  • Running External Programs
  • References
  • Terse Perl

Makefile

1
  • Makefile Tutorial

Interview Questions

2
  • SystemVerilog Interview Questions
  • Verilog Interview Questions

Handwritten Notes

3
  • Perl (Scripting)
  • Linting
  • CMOS Logic Design
View Categories
  • Home
  • Tutorials
  • System Verilog
  • Type Casting

Type Casting

< 1 min read

What is Type Casting? #

Type casting is the process of converting one data type into another. It is especially useful when working with different bit-widths, enum, struct, or class types.

SystemVerilog supports two types of casting:

  1. Static Casting (done at compile-time)
  2. Dynamic Casting (done at runtime, especially with classes).

Why Type Casting is Important #

  • Prevents mismatched assignments
  • Ensures correct data size and interpretation
  • Enables class polymorphism
  • Helps in hardware modeling (e.g., casting bit-vectors, enums)

1. Static Casting #

Static casting is used to convert values at compile-time between compatible types like enums, bit-vectors, and integers.

Syntax:

<data_type'(expression)

Example:

module static_cast;
  int a = 65;          // 32-bit integer
  byte b;              // 8-bit integer

  initial begin
    b = byte'(a);      // Static cast from int to byte
    $display("Value of b = %0d", b);  
  end
endmodule

Output:

Value of b = 65

Explanation: #

  • a is an int (32-bit)
  • b is a byte (8-bit)
  • We convert a to byte using byte'(a)
  • Since 65 fits in 8 bits, b gets the value 65

2. Dynamic Casting using $cast #

Dynamic casting is used at runtime, mostly with class handles. It checks if the object types are compatible before casting.

Syntax:

$cast(Destination, Source)

Example:

Updated on August 3, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
Data TypesArrays

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents
  • What is Type Casting?
  • Why Type Casting is Important
    • 1. Static Casting
    • Explanation:
    • 2. Dynamic Casting using $cast

Archives

  • May 2025

Categories

  • Slider Post
  • Uncategorized

Copyright @ Asicguru Ventures by Misbah WP | Proudly powered by WordPress