%% Combine Bytes into 32-bit Unsigned Integer
% Use bitor and bitshift to pack four 8-bit bytes into the 32-bit integer they make up.
%
% Create four bytes of data. Specify the data with hexadecimal literals, using the -u32 suffix to specify that the data should be stored as uint32. Each byte contains 8 bits worth of data.

byte4 = 0x87u32; 
byte3 = 0x65u32; 
byte2 = 0x43u32; 
byte1 = 0x21u32;

%
% Start by adding the first byte as the first 8 bits of a 32-bit unsigned integer.

packedNum = byte1;

%
% Next, pack the other three bytes into packedNum, using bitshift to shift the bytes to the proper locations, and bitor to copy the bits over.

packedNum = bitor(packedNum,bitshift(byte2,8));
packedNum = bitor(packedNum,bitshift(byte3,8*2));
packedNum = bitor(packedNum,bitshift(byte4,8*3));

%
% View the packed 32-bit integer.

format hex
packedNum

%
% Copyright 2020 The MathWorks, Inc.