File Exchange

image thumbnail

Byte manipulation and Endian conversion in MATLAB

version 1.0.0.1 (8.63 KB) by Gautam Vallabha
A demonstration of MATLAB's built-in facilities for unpacking integers into individual bytes (and vi

7 Downloads

Updated 01 Sep 2016

View License

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

Comments and Ratings (4)

Very helpful, thanks.

Help on the typecast use was helpful

Max

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.

Updates

1.0.0.1

Updated license

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor