Convert conductor value to integer in verilog

I want to convert the data in a wire to an integer. For instance:

wire [2:0] w = 3'b101; 

I need a method that converts it to "5" and stores it in integer form. How can I do this better than this:

 j=1; for(i=0; i<=2; i=i+1) begin a=a+(w[i]*j); j=j*2; end 

Also, how do I convert it back to binary as soon as I have a value in an integer? It seems awkward. Thanks.

+6
source share
1 answer

Easy! The conversion is done automatically in verilog if you assign an integer. In verilog, all data types are just bitwise collection.

 integer my_int; always @( w ) my_int = w; 
+10
source

Source: https://habr.com/ru/post/885921/