- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi

How can I divide a negative number by 32 ? without using a dsp ip core. thanksLink Copied

5 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

By dividing the number by 32...

Division by a power of two is simply removing that many LSBs from the number, it takes no combinational logic what-so-ever. 32 is 2^5, so you need only remove the lower 5 bits of the number and the division is done. If you want the output width to stay the same, then for a signed number, simply replicate the MSB to fill the gap.```
{{(5){a}},a}
```

Where "MSB" is the width-1 of the signal you are dividing. Alternatively, do an arithmetic shift: ```
$signed(a)>>>5
```

Will do the same thing. The examples I gave are in Verilog. I realise this is the VHDL forum, but I am not familiar with the language. There will be an equivalent in VHDL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

the easiest way, would just be a divide. divide by 2^n infers a bit shift.

```
signal ip, s : signed(31 downto 0);
s <= ip / 32;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

this is what I did in VHDL: what do you think?

1.shift right 5 bits. 2.fill this 5MSBs slope(10 downto 0) <= delta_y (15 downto 5) ; slope(15 downto 11) <= delta_y(15) & delta_y(15) & delta_y(15) & delta_y(15) & delta_y(15);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

It will work just fine. Is there any reason you dont want to use the signed data type? then you wouldnt need to pad the sign bit as you can use the resize function:

slope <= resize( delta_t(15 downto 5), slope'length);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page