Watch this Author's files
Dave Your solutions are good but only for positive numbers.
decimal to Q15 -> dec2hex(y) -> y must be a nonnegative integer.
Q15 to decimal -> for negative numbers return wrong result.
Best regards, S.L.
Unfortunately for me, this solution requires the fixed-point toolbox (for bin2num, or hex2num). This is my solution: decimal to Q15:
y=int16(x*2^15); % then use dec2hex(y) if you want hex format
Q15 to decimal:
% use hex2dec(x) first if x is in hex format x=double(x); y=x*2^-15;
Is there any reason this should not work?
Dave
VERY USEFUL, Thank you.
Please add a proper help section, including a H1 line, input and output requirements, and an example as well as internal comments, if you want that anyone else but you will find this code useful.
Contact us at files@mathworks.com