4.0

4.0 | 2 ratings Rate this file 5 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)

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

| 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).
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

Contact us at files@mathworks.com