16bit signed numbers to 8-bit unsigned number conversion

Anything about FPGA boards, like how to assemble SMD components, find low-voltage regulators, FPGA configuration...

16bit signed numbers to 8-bit unsigned number conversion

Postby anch » Mon Jun 21, 2010 5:39 am

Hi All,

I need some hardware logic for the conversion of signed 16-bit number to unsigned 8-bit number. I'll really appreciate if someone could provide me that particular logic.


Regards
Adnan
anch
 
Posts: 9
Joined: Thu Oct 29, 2009 5:28 pm

Postby WadeH » Fri Jun 25, 2010 5:11 pm

The question needs more details.
Your input format presents values from -32768 to +32767 and your output format can only represent 0 to 255 .
What happens for inputs outside that range?

One very restrictive interpretation would be:
"Negative inputs return zero and positive values saturate at 255"

Code: Select all
assign Uns8B[7:0] = (Sgn16B[15]) ? 8'b0 : (Sgn16B > 255) ? 8'd255 : Sgn16[7:0];;


Another possibility would be:
"the input-range is mapped to the output-range, i.e., -32768-> 0 and 32767 -> 255":

Code: Select all
assign Uns8B[7:0] = {~Sgn16B[15],Sgn16B[14:8]};

(neither code was tested and both assume 2's complement numbers.)
WadeH
 
Posts: 13
Joined: Fri Apr 22, 2005 3:17 pm

Postby anch » Sat Jun 26, 2010 6:09 pm

thanks a lot WadeH, i am doing the same ... i just wanted to confirm. intermediate results of 2d image convolution are signed 16-bit numbers ... final result has to be converted into 8bit unsigned numbers thats why i need this conversion..


Regards
Adnan
anch
 
Posts: 9
Joined: Thu Oct 29, 2009 5:28 pm


Return to General boards