![]() |
|
|
|
#1 |
|
Hi all;
I use the "numeric_std". how can I conver an "unsigned 8 bit" to a "signed 9-bit". a :unsigned(7 down to 0); aa, b,c :signed(8 down to 0); if i write: aa<= to_signed(a,9); then i got wrong result for c<= aa-b; when aa is negative. thanks. spartan |
|
|
|
|
#2 |
|
Posts: n/a
|
spartan a écrit:
> Hi all; > I use the "numeric_std". how can I conver an "unsigned 8 bit" to a "signed > 9-bit". > > a :unsigned(7 down to 0); > aa, b,c :signed(8 down to 0); > if i write: > aa<= to_signed(a,9); > then i got wrong result for > c<= aa-b; > when aa is negative. > > thanks. > > Signed & unsigned types are std_logic vectors. Function to_signed only converts from integer to signed vectors. Your problem is easily solved this way: aa <= signed('0' & a); (add the sign bit and cast the result to signed) -- ____ _ __ ___ | _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le - | | | | | (_| |_| | Invalid return address: remove the - |_| |_|_|\__|\___/ Nicolas Matringe |
|
|
|
#3 |
|
Posts: n/a
|
You are right but this work just when "a" is possitive. suppose that a is
1000-0001(-127) aa would be 0-1000-0001 while we expected it to be 1-1000-0001. when i use arith_std_logic and conv_signed(a,9)it works, but i nees to use numeric. Any idea? Thanks a lot. spartan |
|
|
|
#4 |
|
Posts: n/a
|
How about this
aa <= signed(a(7) & a); Symon |
|
|
|
#5 |
|
Posts: n/a
|
> You are right but this work just when "a" is possitive. suppose that a is
> 1000-0001(-127) aa would be 0-1000-0001 while we expected it to be > 1-1000-0001. > when i use arith_std_logic and conv_signed(a,9)it works, but i nees to use > numeric. > Any idea? I think you need to rethink your problem. If a is unsigned, then it is never negative and the following is correct: signal a :unsigned(7 downto 0); aa <= signed('0' & a); However, the following is not correct when a is a large positive number and b is a large negative number. signal a : unsigned(7 downto 0); signal b,c : signed(8 downto 0); c <= signed('0' & a) - b ; C needs to be one bit bigger. The following should work. signal a : unsigned(7 downto 0); signal b : signed(8 downto 0); signal c : signed(9 downto 0); c <= signed("00" & a) - b ; You could also extend b, however, only one of the operands needs to match the size of the result: c <= signed("00" & a) - (b( On the otherhand, if a is signed (as indicated by your concern about it being negative), then you need either of the following two assignments: signal a : signed(7 downto 0); signal b : signed(8 downto 0); signal c1, c2 : signed(9 downto 0); c1 <= a - (b( c2 <= (a(7) & a(7) & a) - (b( Cheers, Jim -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Jim Lewis Director of Training private.php?do=newpm&u= SynthWorks Design Inc. http://www.SynthWorks.com 1-503-590-4787 Expert VHDL Training for Hardware Design and Verification ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ Jim Lewis |
|
|
|
#6 |
|
Posts: n/a
|
"spartan" <> wrote in message news: lkaboutprogramming.com .... > Hi all; > I use the "numeric_std". how can I conver an "unsigned 8 bit" to a "signed > 9-bit". > > a :unsigned(7 down to 0); > aa, b,c :signed(8 down to 0); > if i write: > aa<= to_signed(a,9); > then i got wrong result for > c<= aa-b; > when aa is negative. > > thanks. > If "a" is unsigned then it is always non-negative. So, to convert it to 9-bit long signed, just pad a '0' on the left. The following statement should do the job: aa <= signed(resize(a,9)); If, on the other hand, you really want "a" to be treated as signed in this case, then try the following: aa <= resize(signed(a),9); This will extend the sign bit to the left instead of padding with '0'; Charles Bailey |
|
|
|
#7 |
|
Posts: n/a
|
Assuming you want to interpret the 8 bit unsigned as a signed value, and sign
extend it then to 9 bits: aa<= resize(signed(a),9); spartan wrote: > Hi all; > I use the "numeric_std". how can I conver an "unsigned 8 bit" to a "signed > 9-bit". > > a :unsigned(7 down to 0); > aa, b,c :signed(8 down to 0); > if i write: > aa<= to_signed(a,9); > then i got wrong result for > c<= aa-b; > when aa is negative. > > thanks. -- --Ray Andraka, P.E. President, the Andraka Consulting Group, Inc. 401/884-7930 Fax 401/884-7950 http://www.andraka.com "They that give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin, 1759 Ray Andraka |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error: expected constructor, destructor or type conversion before '(' token | suse | Software | 0 | 03-09-2009 03:25 AM |
| Conversion tool:Flash2Video | hely0123 | Software | 0 | 11-01-2007 03:30 AM |
| VOB Conversion Help Request | Ryton | DVD Video | 1 | 03-19-2007 10:37 AM |
| VHS conversion: PC capture card, or standalone burner? | Patrick Neve | DVD Video | 10 | 05-16-2006 09:34 AM |
| file conversion size/quality issues | RichA | DVD Video | 0 | 03-02-2005 05:24 AM |