Code covered by the BSD License  

Highlights from
Q15 to decimal converter

3.33333

3.3 | 3 ratings Rate this file 5 Downloads (last 30 days) File Size: 1.22 KB File ID: #18413

Q15 to decimal converter

by Szymon Leja

 

22 Jan 2008 (Updated 22 Jan 2008)

Silmple function that converts an value from Q15 to decimal.

| Watch this File

File Information
Description

Converts any Q15 value (hexadecimal or binary) to decimal integer.

y = q152dec(x , form)

Input arguments of function:
x - its hexadecimal or binary representation stored in a MATLAB string

form - dependent on representation of input argument (hexadecimal or binary) take 'hex' or 'bin'

Valu of function:
y - decimal integer

EXAMPLE:
>> q152dec('C000','hex')

ans =

   -0.5000

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
22 Jan 2008 Jos x@y.z

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.

24 Jan 2008 A B

VERY USEFUL, Thank you.

23 Feb 2008 Dave Hardell

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

24 Feb 2008 Szymon Leja

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.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
signal processing Szymon Leja 22 Oct 2008 09:43:56
q15 Szymon Leja 22 Oct 2008 09:43:56
dec Szymon Leja 22 Oct 2008 09:43:56
converter Szymon Leja 22 Oct 2008 09:43:56
decimal Szymon Leja 22 Oct 2008 09:43:56
hexadecimal Szymon Leja 22 Oct 2008 09:43:56
binary Szymon Leja 22 Oct 2008 09:43:56
integers Szymon Leja 22 Oct 2008 09:43:56
companion Szymon Leja 22 Oct 2008 09:43:56

Contact us at files@mathworks.com