电线值转换为Verilog内的整数 [英] converting a wire value to an integer in verilog

查看:705
本文介绍了电线值转换为Verilog内的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲中的数据线转换为整数。例如:

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

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

我想,在一个整数转换成5,并将其存储的方法。我怎么能做到这一点以更好的方式比这个:

I want a method that converts this to '5' and stores it in an integer. How can I do that in a better way 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 once I have the value in an integer? This seems a clumsy way. Thank you.

推荐答案

简单!如果分配到一个整数转换的Verilog自动的。在Verilog中,所有的数据类型都在位只是集合。

Easy! Conversion is automatic in verilog if you assign to an integer. In verilog, all the data types are just collection on bits.

integer my_int;
always @( w )
    my_int = w;

这篇关于电线值转换为Verilog内的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆