Easy type conversion question for you guys

Discussion in 'VHDL' started by Shannon, Jul 3, 2007.

  1. Shannon

    Shannon Guest

    I have:

    Integer_variable: OUT INTEGER RANGE 0 TO 65535;

    and

    TYPE reg_type IS ARRAY (0 TO 12) OF STD_LOGIC_VECTOR(var1'RANGE);
    SIGNAL regs : reg_type;

    and what I want to accomplish is:

    Integer_variable <= to_integer(unsigned(regs(6) & regs(5) & regs(4) &
    regs(3)));

    Is there a way to accomplish this with just type casting? I'd rather
    not change the types assigned to 'Integer_variable and 'regs'.

    TYIA
    Shannon
    Shannon, Jul 3, 2007
    #1
    1. Advertising

  2. Shannon <> writes:

    Hi Shannon,

    Sorry - no answers, only questions!

    > I have:
    >
    > Integer_variable: OUT INTEGER RANGE 0 TO 65535;
    >
    > and
    >
    > TYPE reg_type IS ARRAY (0 TO 12) OF STD_LOGIC_VECTOR(var1'RANGE);


    How wide are the vectors?

    > SIGNAL regs : reg_type;
    >
    > and what I want to accomplish is:
    >
    > Integer_variable <= to_integer(unsigned(regs(6) & regs(5) & regs(4) &
    > regs(3)));
    >


    Have you tried it? What doesn't work?

    > Is there a way to accomplish this with just type casting? I'd rather
    > not change the types assigned to 'Integer_variable and 'regs'.
    >


    I think what you've written ought to work...

    Cheers,
    Martin

    --

    TRW Conekt - Consultancy in Engineering, Knowledge and Technology
    http://www.conekt.net/electronics.html
    Martin Thompson, Jul 4, 2007
    #2
    1. Advertising

  3. Shannon

    Shannon Guest

    On Jul 4, 2:38 am, Martin Thompson <> wrote:
    > Shannon <> writes:
    >
    > Hi Shannon,
    >
    > Sorry - no answers, only questions!
    >
    > > I have:

    >
    > > Integer_variable: OUT INTEGER RANGE 0 TO 65535;

    >
    > > and

    >
    > > TYPE reg_type IS ARRAY (0 TO 12) OF STD_LOGIC_VECTOR(var1'RANGE);

    >
    > How wide are the vectors?
    >
    > > SIGNAL regs : reg_type;

    >
    > > and what I want to accomplish is:

    >
    > > Integer_variable <= to_integer(unsigned(regs(6) & regs(5) & regs(4) &
    > > regs(3)));

    >
    > Have you tried it? What doesn't work?
    >
    > > Is there a way to accomplish this with just type casting? I'd rather
    > > not change the types assigned to 'Integer_variable and 'regs'.

    >
    > I think what you've written ought to work...
    >
    > Cheers,
    > Martin
    >
    > --
    >
    > TRW Conekt - Consultancy in Engineering, Knowledge and Technologyhttp://www.conekt.net/electronics.html


    Sorry to bother anyone with this post. The above DOES work. I am too
    embarrassed to explain why I was having problems.

    Martin: Actually you bring up a very good point. I realized it after
    I posted this message. My use of 'var1'RANGE' is nice and generic but
    things will break if 'RANGE' is anything other than 8 bits. I'm not
    sure how to fix this, but for now regs are 8bits and
    'Integer_variable' is an integer. I put a note in my code and I'll
    revisit this when I'm doing my clean-up pass.

    Shannon
    Shannon, Jul 5, 2007
    #3
  4. Shannon wrote:

    > Sorry to bother anyone with this post. The above DOES work. I am too
    > embarrassed to explain why I was having problems.


    That's poster's remorse :)
    Happens to me all the time.
    There is something about clicking that send button
    that provides instant enlightenment.

    -- Mike Treseler
    Mike Treseler, Jul 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    4,207
    Renaud Pacalet
    Oct 3, 2003
  2. Mike Dee
    Replies:
    0
    Views:
    372
    Mike Dee
    Nov 30, 2005
  3. -
    Replies:
    3
    Views:
    944
    Grant Wagner
    Jul 15, 2003
  4. Travis Newbury

    I just love you guys....

    Travis Newbury, Jul 23, 2005, in forum: HTML
    Replies:
    4
    Views:
    463
    Travis Newbury
    Jul 23, 2005
  5. John Salerno

    I think you guys converted me...

    John Salerno, Feb 4, 2006, in forum: HTML
    Replies:
    11
    Views:
    634
    Alan J. Flavell
    Feb 6, 2006
Loading...

Share This Page