Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - how to make a package(byte -> integer)

 
Thread Tools Search this Thread
Old 04-06-2005, 04:03 PM   #1
Default how to make a package(byte -> integer)


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
  Reply With Quote
Old 04-06-2005, 05:33 PM   #2
charles.elias@wpafb.af.mil
 
Posts: n/a
Default Re: how to make a package(byte -> integer)

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



charles.elias@wpafb.af.mil
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Make about $60,000 in 6 months (i made 20,000).txt (1/1) mr_cool DVD Video 2 03-29-2008 02:11 AM
MAKE HONEST LEGAL MONEY WITH $6.00 linnea_damerau@hotmail.com DVD Video 0 05-18-2006 10:13 AM
MAKE FAST MONEY LEGALLY!!!!!!!!!!!!!!!!!! will_strip_4_banannas_boys@yahoo.com DVD Video 0 02-02-2006 07:03 PM
MAKE FAST MONEY LEGALLY!!!!!!!!!!!!!!!!!! will_strip_4_banannas_boys@yahoo.com DVD Video 0 02-02-2006 06:04 PM
make a lot of money fast! baseballerwc@yahoo.com DVD Video 0 01-31-2006 07:16 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46