# Casting into an enum

**URL:** <https://verificationacademy.com/forums/t/casting-into-an-enum/33221>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [June 15, 2017, 10:33pm UTC](https://verificationacademy.com/forums/t/casting-into-an-enum/33221 "2017-06-15T22:33:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![raysalemi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/35a633/32.png) [@raysalemi](https://verificationacademy.com/forums/u/raysalemi)\
**Post date:** [June 16, 2017, 3:02pm UTC](https://verificationacademy.com/forums/t/casting-into-an-enum/33221/3 "2017-06-16T15:02:40Z")

</div>

_In reply to [silverace99](https://verificationacademy.com/forums/t/casting-into-an-enum/33221/2):_

Hi,

It appears that part of the example code is missing. The code on the [github repository](https://github.com/rdsalemi/uvmprimer.git) for the examples looks like this:

```verilog

    $display("COMMAND MONITOR: A:0x%2h B:0x%2h op: %s", A, B, cmd.op.name());
    ap.write(cmd);
  endfunction : write_to_monitor

/// The function below is missing in your example above

   function operation_t op2enum(bit[2:0] op);
      case(op)
        3'b000 : return no_op;
        3'b001 : return add_op;
        3'b010 : return and_op;
        3'b011 : return xor_op;
        3'b100 : return mul_op;
        3'b111 : return rst_op;
        default : $fatal($sformatf("Illegal operation on op bus: %3b",op));
      endcase // case (op)
   endfunction : op2enum

   function new (string name, uvm_component parent);
      super.new(name,parent);
   endfunction

endclass : command_monitor

```

Best,  
Ray

---

_[View the full topic](https://verificationacademy.com/forums/t/casting-into-an-enum/33221)._
