SystemVerilog Enumerated Type conversion - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

203


18
 
1
// Code your testbench here
2
// or browse Examples
3
4
module enum_method; 
5
  typedef enum {RED, BLUE, GREEN} COLOR_E;
6
  COLOR_E color, c2;
7
  integer c;
8
  initial begin
9
    c = color; // Convert from enum to integer
10
    c++; // Increment integer
11
    if (!$cast(color, c)) begin // Cast integer back to enum
12
      $display("Cast failed for c=%0d", c);
13
    end
14
    $display("Color is %0d & %0s", color, color.name);
15
    c2 = COLOR_E'(c); // No type checking done
16
  end
17
18
endmodule 
xxxxxxxxxx
1
 
1
// Code your design here
2
2814 views and 1 likes     
A short description will be helpful for you to remember your playground's details
 
100:0