VHDL code for truncation

Status
Not open for further replies.
It all depands on whats your number representation code and what you want to achieve....
 

sir, for example input bit:10 bit,output bit:8 bit... means how to reduce this truncated 2 bits effects in information?
 

you can reduce the truncate error by rounding instead of choping

eg: output <= input(9 downto 2) --! choping
output <= input(9 downto 2 ) + 1 if input(1 downto 0) > "10" ..... --! rounding todo: handle if input is signed
 

easiest rounding method is to truncate to LSB -1, then add 1, then truncate the LSB.

So for 10 bits down to 8 bits:

Truncate to 9 bits
+1
truncate to 8 bits

Then you have a rounded result.

Remember, that with every truncate, you will have an error of +- 0.5. If you chain several truncations, especially if the following calculation is a multiply, you compound the errors.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…