MATLAB Examples

Pack and Unpack Data Example for MATLAB

This example shows how to pack and unpack data using the provided packData and unpackData functions

Contents

Set the input to an int8 1x2 vector

inputData = int8([-127 127]);
inputDataType = 'int8';
inputSize = 2;

Packing Data

Then pack the int8 vector into a uint8 1x2 vector

packedData = packData(inputData,inputDataType,inputSize)
packedData =

  129  127

Unpacking Data

Unpacking the array of bytes, and we get the original int8 1x2 array

unpackedData = unpackData(packedData,inputDataType,inputSize)
unpackedData =

 -127  127