5.0

5.0 | 1 rating Rate this file 116 downloads (last 30 days) File Size: 7.46 KB File ID: #17661

swapbytes C-mex function

by James Tursa

 

22 Nov 2007 (Updated 05 Aug 2009)

Code covered by BSD License  

swapbytes(X1,X2,...) reverses byte ordering of each element, little-endian values to/from big-endian

Download Now | Watch this File

File Information
Description

swapbytes is a self-building C-mex function that mimics the MATLAB intrinsic function of the same name, reversing the byte ordering of each element in array X1, X2, ..., converting little-endian values to big-endian (and vice versa). Mainly intended for those users with older version of MATLAB that do not have this intrinsic function available, but there are extensions that may be of interest to other users as well:

1) For structures and cell arrays, each component or cell is individually converted. Other classes (e.g., vpa, function handles, etc.) are not converted; a deep copy is returned instead.

2) swapbytes takes any number of input arguments; there must be the same number of matching output arguments (except in the special case of one input argument and no output arguments, in which case the answer is returned in ans).

3) swapbytes will convert the complex portion of variables as well as the real portion.

4) swapbytes works with sparse matrices.

For users with later versions of MATLAB, this mex file will clash with the actual intrinsic of the same name. If you want to use this mex file and still have access to the MATLAB intrinsic, simply rename this file and the help file to something unique, like swapbytesx.c and swapbytesx.m

swapbytes runs up to 3x faster than the MATLAB intrinsic swapbytes for some versions of MATLAB.

Note that swapbytes is a self-building C-mex function ... you don't have to know anything about C to build or use it.

MATLAB release MATLAB 7.2 (R2006a)
Other requirements Any C compiler, such as the built in lcc compiler. Note that swapbytes is self-building ... you don't have to know anything about C to build or use swapbytes.
Zip File Content  
Other Files license.txt,
swapbytes.c,
swapbytes.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
13 Nov 2008 Pei  
Please login to add a comment or rating.
Updates
05 Aug 2009

Added sparse matrix support, and BSD license.

Tag Activity for this File
Tag Applied By Date/Time
external interface James Tursa 22 Oct 2008 09:36:30
swapbytes James Tursa 22 Oct 2008 09:36:30
reverse byte ordering James Tursa 22 Oct 2008 09:36:30
bigendian James Tursa 22 Oct 2008 09:36:30
littleendian James Tursa 22 Oct 2008 09:36:30
endian James Tursa 05 Aug 2009 11:23:24
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com