+ Post New Thread

Results 1 to 8 of 8

- 7th March 2017, 10:17 #1

- Join Date
- Jan 2016
- Posts
- 38
- Helped
- 1 / 1
- Points
- 406
- Level
- 4

## how to call decimal values in verilog

hy

i am working in a image processing based project using FPGA. i want to call my features into addition block which are decimals in the range of 0.1 to 0.9. Can anyone tell me some techniques to convert these numbers into fixed point binary?

- 7th March 2017, 10:17

- 7th March 2017, 10:28 #2

- Join Date
- Apr 2014
- Posts
- 8,240
- Helped
- 1991 / 1991
- Points
- 40,308
- Level
- 49

## Re: how to call decimal values in verilog

Hi,

simply use "1...9" as integers.

And imagine as there was a "0." before it.

Or use them as integers and divide them by 10...if you really need this.

****

Maybe you need to give a bit more information, why you especially need to know that it is a value between 0 and 1.

Klaus

- 8th March 2017, 03:28 #3

- Join Date
- Jul 2014
- Posts
- 142
- Helped
- 7 / 7
- Points
- 1,137
- Level
- 7

## Re: how to call decimal values in verilog

hi,

sometimes i will use this for conversion

http://www.exploringbinary.com/binary-converter/

then what is the fixed integer & fractional length ?

regards

2 members found this post helpful.

- 8th March 2017, 03:28

- 8th March 2017, 06:48 #4

- Join Date
- Jan 2016
- Posts
- 38
- Helped
- 1 / 1
- Points
- 406
- Level
- 4

## Re: how to call decimal values in verilog

can anyone explain about the roundoff to the nearest power of 2 concept? can i use this for converting my decimals into rounded integer and then into binary

- 8th March 2017, 17:12 #5

- Join Date
- Sep 2013
- Location
- USA
- Posts
- 5,486
- Helped
- 1375 / 1375
- Points
- 24,537
- Level
- 38

## Re: how to call decimal values in verilog

Nearest power of two is finding the 2^N that is nearest to your number.

e.g.

Code:2 => 2^1 (2) 5 => 2^2 (4), or 2^3 (8, for round up) 13 => 2^4 (16)

BTW in hardware all decimal numbers are stored as binary values, there are no 10 state FFs. So if you look at the following code:

Code:wire [3:0] a; assign a = 10; // 10 in binary is 1010 // a[0] = 1'b0 // a[1] = 1'b1 // a[2] = 1'b0 // a[3] = 1'b1

1 members found this post helpful.

- 8th March 2017, 17:12

- 9th March 2017, 03:50 #6

- Join Date
- Jan 2016
- Posts
- 38
- Helped
- 1 / 1
- Points
- 406
- Level
- 4

## Re: how to call decimal values in verilog

can you tell me how to choose an effective scaling factor? whether it should be only *10 s or any other number?

- 9th March 2017, 16:19 #7

- Join Date
- Sep 2013
- Location
- USA
- Posts
- 5,486
- Helped
- 1375 / 1375
- Points
- 24,537
- Level
- 38

## Re: how to call decimal values in verilog

You scale based on the number of bit of precision you require.

1 members found this post helpful.

- 9th March 2017, 18:08 #8

- Join Date
- Dec 2013
- Location
- St-Petersburg, Russia
- Posts
- 15
- Helped
- 4 / 4
- Points
- 669
- Level
- 5

## Re: how to call decimal values in verilog

Fixed point arithmetics is absoultely the same as integer arithmetics, in fact it IS integer arithmetics. It's up to you where to put decimal point.

1 members found this post helpful.

+ Post New Thread

Please login