how to make a package(byte -> integer)

Discussion in 'VHDL' started by shin, Apr 6, 2005.

  1. shin

    shin Guest

    package sample is
    type byte is range 00000000 to 1111111;
    type integer is range -2147483647 to 2147483647;
    function byte_to_integer(x : byte) return integer;
    end sample;

    PACKAGE BODY sample IS
    function byte_to_integer (x : byte) return integer is
    ++++variable sum : integer :=0;
    begin
    for i in 0 to 7 loop
    if x(i)='1' then
    sum :=sum+2**i;
    end if;
    end loop;
    return sum;
    end ;
    end sample;


    -------------- ÀÎÅÍ³Ý Ä«¸®½º¸¶ KORNET -------------
    shin, Apr 6, 2005
    #1
    1. Advertising

  2. shin

    Guest

    shin wrote:
    > package sample is
    > type byte is range 00000000 to 1111111;
    > type integer is range -2147483647 to 2147483647;
    > function byte_to_integer(x : byte) return integer;
    > end sample;
    >
    > PACKAGE BODY sample IS
    > function byte_to_integer (x : byte) return integer is
    > ++++variable sum : integer :=0;
    > begin
    > for i in 0 to 7 loop
    > if x(i)='1' then
    > sum :=sum+2**i;
    > end if;
    > end loop;
    > return sum;
    > end ;
    > end sample;
    >
    >
    > -------------- ì¸í„°ë„· 카리스마 KORNET -------------

    You have at least 2 problems here:

    1. You have created a type "integer" that already exists. When you
    then declare a variable of type integer you get an error. Why not use
    the existing integer type?

    2. Your type byte cannot accessed as if it were an array. If you
    declare byte as a subtype of std_logic vector, for example:

    subtype byte is std_logic_vector( 7 downto 0 );

    then you can use a loop variable as an index as you did in your code.

    Best regards,

    Charles
    , Apr 6, 2005
    #2
    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. Andreas
    Replies:
    1
    Views:
    843
    Jonathan Bromley
    May 4, 2004
  2. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,235
    Roedy Green
    Aug 5, 2003
  3. Johannes Zellner
    Replies:
    22
    Views:
    3,576
  4. jt
    Replies:
    3
    Views:
    921
    Keith Thompson
    May 23, 2005
  5. Polaris431
    Replies:
    8
    Views:
    753
    SM Ryan
    Dec 4, 2006
Loading...

Share This Page