![]() |
|
|
|||||||
![]() |
VHDL - how to make a package(byte -> integer) |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |