image thumbnail
from intbitcopy and uintbitcopy by James Tursa
Exact bit copy of variable into signed int__ or unsigned uint__ of same element size

uintbitcopy.m
%/*************************************************************************************
% *
% * MATLAB (R) is a trademark of The Mathworks (R) Corporation
% *
% * Function:    uintbitcopy
% * Filename:    uintbitcopy.c
% * Programmer:  James Tursa
% * Version:     1.0
% * Date:        November 13, 2007
% * Copyright:   (c) 2007 by James Tursa
% * Permission:  Permission is granted to freely distribute and use this code
% *              as long as the header information is included.
% *
% * uintbitcopy is a mex function that copies arguments into unsigned integer
% * copies of the same byte length using an exact bit copy. Variable types
% * are copied as follows:
% *
% *   double  --> uint64
% *   single  --> uint32
% *   uint64  --> uint64
% *   int64   --> uint64
% *   uint32  --> uint32
% *   int32   --> uint32
% *   uint16  --> uint16
% *   int16   --> uint16
% *   char    --> uint16
% *   uint8   --> uint8
% *   int8    --> uint8
% *   logical --> uint8
% *
% * 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. uintbitcopy takes any number
% * of input arguments; there must be the same number of matching output
% * arguments. uintbitcopy is similar to typecast, except that individual
% * element data length is preserved. Also, uintbitcopy will copy the
% * complex portion of variables as well as the real portion.
% *
% * Building:
% *
% * >> mex -setup
% *   (then follow instructions to select a C compiler of your choice)
% * >> mex uintbitcopy.c
% *
% * Syntax:
% *
% *   Y = uintbitcopy(X)
% *   [Y1 Y2] = uintbitcopy(X1,X2)
% *   [Y1 Y2 Y3] = uintbitcopy(X1,X2,X3)
% *       :             :
% *      etc           etc
% *
% ****************************************************************************/

Contact us at files@mathworks.com