UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Contributor
Contributor
3,743 Views
Registered: ‎03-19-2015

get ap_fixed decimal value

Jump to solution

Hello,

how can I get decimal value from ap_fixed?

for example I have:

ap_ufixed<8, 4> my_ufixed;

and I want to save it to two separate variables:

ap_uint<4> my_uint;

ap_uint<4> my_dec;

I know I can do:

my_uint = my_ufixed.to_int()

but how can I get decimal value?

I'm sure there is an easy solution, but I somehow cannot find it.

0 Kudos
1 Solution

Accepted Solutions
Explorer
Explorer
6,423 Views
Registered: ‎07-13-2015

Re: get ap_fixed decimal value

Jump to solution

You should be able to do this:

 

ap_uint<4> my_dec = my_ufixed.range(3,0);

Obviously care must be taken when dealing with signed fixed-point; you'll have to decide how you want to handle that if you ever do need to use it.

 

If you want the actual decimal value (rather than the decimal value shifted up to become an integer) then the code would be:

ap_ufixed<4,0> my_dec;
my_dec.range() = my_ufixed.range(3,0);

For an input of 3.0625 (binary 0011.0001) the first approach would give you a value of 1, whereas the second would give a value of 0.0625.

0 Kudos
1 Reply
Explorer
Explorer
6,424 Views
Registered: ‎07-13-2015

Re: get ap_fixed decimal value

Jump to solution

You should be able to do this:

 

ap_uint<4> my_dec = my_ufixed.range(3,0);

Obviously care must be taken when dealing with signed fixed-point; you'll have to decide how you want to handle that if you ever do need to use it.

 

If you want the actual decimal value (rather than the decimal value shifted up to become an integer) then the code would be:

ap_ufixed<4,0> my_dec;
my_dec.range() = my_ufixed.range(3,0);

For an input of 3.0625 (binary 0011.0001) the first approach would give you a value of 1, whereas the second would give a value of 0.0625.

0 Kudos