Level: Rookie

Joined: Mon. Sep 16, 2019

Posted by MuhammedElmaghraby:
Mon. Mar 23, 2020 - 06:51 PM
Hello guys , Today i decided to study the Fixed point math , so here is a code i am working on ... i am assuming that i have 2 variables x =1.2 and z =3.2 but they are scaled by 16 so X=19 and Z=51 ,

I want to Add X+Z and store the result in Result variable which is going to be equal to 70 which is in the form of UQ4_4(UQ4.4) iam working on unsigned Q ...

70 is represented in binary as 0100.0110 ,,, the decimal point is just virtual my problem is how can i get the fractional part?

i did ANDing the 70 with 0x0F to extract the 4 fractional bits which is equal to 6 in decimal but the value should be 0.375 ... so when i divide 6 / 16 I get 0.375 .. the problem is how can i get 0.375 on AVR to display 4.375 which is an approximated result of adding 1.2 +3.2

## Tags:

Last Edited: Mon. Mar 23, 2020 - 07:58 PM