4.0

4.0 | 2 ratings Rate this file 93 downloads (last 30 days) File Size: 8.63 KB File ID: #17569

Byte manipulation and Endian conversion in MATLAB

by Gautam Vallabha

 

16 Nov 2007 (Updated 19 Nov 2007)

Code covered by BSD License  

A demonstration of MATLAB's built-in facilities for unpacking integers into individual bytes (and vi

Download Now | Watch this File

File Information
Description

MATLAB has several function that allow byte-level manipulation of numeric data types (such as DOUBLE, INT32, or UINT16). These can be used to easily convert a multibyte integer into individual bytes or vice versa, check the endian-ness of a system, or convert between big and little-endian formats.

This submission consists of an m-file (ByteConversion.m) and its published HTML version (ByteConversion.html). These files demonstrate the different byte-manipulation abilities.

Table of Contents
-----------------

* Creating an integer variable
* Destructive casting - I
* Destructive casting - II
* Non-destructive casting
* Converting an integer to a sequence of bytes
* Converting a floating-point value to a sequence of bytes
* Converting a sequence of bytes to an integer
* Checking the Endianness of the system
* Little-endian and Big-endian conversions
* Help on functions

MATLAB release MATLAB 7.5 (R2007b)
Other requirements The m-file was tested on R2007b (MATLAB 7.5), but the key functions have been available since R14 (MATLAB 7.0).
Zip File Content  
Published M Files Numeric and byte order (endian) conversions in MATLAB
Other Files ByteConversion.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
22 Jan 2008 Arne Michaelsen

Thanks for this example.

I searched the matlab help for 'uint16', 'cast' ... but did not find any link to 'typecast'. No hint how to avoid the clipping. Your example helped a lot.

03 Jun 2009 Max  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
endian Gautam Vallabha 22 Oct 2008 14:39:56
byte order Gautam Vallabha 22 Oct 2008 14:39:56
casting Gautam Vallabha 22 Oct 2008 14:39:56
typecast Gautam Vallabha 22 Oct 2008 14:39:56
litte endian Gautam Vallabha 22 Oct 2008 14:39:56
big endian Gautam Vallabha 22 Oct 2008 14:39:56
 

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