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

3 posts
• Page **1** of **1**

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

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

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"

Another possibility would be:

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

(neither code was tested and both assume 2's complement numbers.)

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

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

Regards

Adnan

- anch
**Posts:**9**Joined:**Thu Oct 29, 2009 5:28 pm

3 posts
• Page **1** of **1**