Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
It depends whether You can or cannot use floating point operations.
If You can do that, simply multiply the floating point value by 2^(number_of_fractional_bits) and convert the result to integer. In C there's a libm function ldexp() as far as I remember, which provides fast multiplication of floating point numbers by powers of two. It works by manipulating number's exponent value directly.
If You want to do this without messing with floating point math, just extract the mantisa, put '1' bit on the left, shift the number left or right according to it's exponent, and finaly multiply it with 1 or -1 depending on sign bit.
To be more precise, if Your mantisa length is M bits, e.g 23 for single precision ieee floating point numbers (24 bits with 'hidden 1', for double precision - ask google, and You have F fractional bits in Your fixed point numbers, then You need to shift the mantisa (with '1' as MSb included) (M - F) bits to the right, if (M-F) is negative, then You need to shift it to the left.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.