Q27 encoding questions


#1

@Sputnki,
Thanks for this, am mostly trying to wrap my head around the comments pertaining to both Bit Shifting, Fixed Point math and Normal range.. The idea is quite new to me so I am looking for a way to visualize it.
Your comment,
"In practice, to do fixed point math with the mathematical 1 corresponding to digital (1<<27) we have to increase the magnitude of our two numbers by 5."

So from what I have worked out so far please correct me if I am wrong, the shift of 27 bit (1<<27) represents something like 1.00000000 with all the zero's representing potential fixed decimal point value from what I think I have worked out is to 8 decimal points. And the rest of the bits 27 to 32 represents the values 1 to 64 giving the normal range number format hence the need to increase the calculating values by a magnitude of 5 over (1<<27) to get to 32. ?

:confounded:


Coding axoloti objects
#2

1<<27 corresponds to 1
1<<28 corresponds to 2
1<<29 corresponds to 4
1<<30 corresponds to 8
1<<31 corresponds to 16 (unsigned) or -16 (signed)


#3

@Sputnki

I have a question about how to fractionals with decimals. For example if I want to swap a dial with a fixed value, for example 34 I can do it like this:

1+(34<<21)

But what if I want to set a fixed value like 34.95? How would I do that?

Thanks!

BTW thank you for this page. Very helpful for a beginner :slight_smile:


#4

Maybe something like:

(int32_t)(34.95f * (1 << 21))

Note: I think that the rounding is the "towards zero" kind.


#5

If that number is constant during the program you could directly calculate its fixed point counterpart in a calculator (like windows standard calculator or maybe typing the operation on google, like 34.95*2^27).


#6

I think that the compiler detects that it is a constant and does this calculation (at compile time) for us.

This way it is possible to keep it more humain readable.


#7

That worked :slight_smile:

@Sputnki

What does the ^ do? I just googled it and it comes up as "circumflex" in Danish, which is used for letters. But yes it is fixed value. You know, instead of having a dial set to the value all the time, might as well fix it internally.

Thanks to both of you.


#8

That's an exponent, you can see it in any calculator like this:


#9

ahh cool :slight_smile: ..................

But I am still not sure what it does..


#10

ive moved this from the replies to the user guide, lets keep questions away from that topic, its better to have specific questions in the dedicated category here.