MATLAB: How to convert 2 byte data to integer

2-byto to integer conversionint16int32int8typecast

I have a two byte data (unsigned) as array.
e.g. x=[255 67]
I read the data from a sensor giving a stream of byte data (unsigned 0 to 255). From them I select corresponding two-byte of data set for necessary parameter calculation.
I want to convert this into an Integer value or a double value to do real mathematic calculations.
I tried with.
x=uint8([1 0]) y=typecast(x,'uint32') % but this gives an error.
if I use: x=uint16([255 67]) y=typecast(x,'uint32')
% answer is
4391167
I don't how to check the answer is correct or not. Or the conversion syntax is correct?
Can anyone give me the code for correct 2-byte data conversion to integer..!

Best Answer

You were nearly there. combining two bytes (uint8) does not make a 32-bit number (uint32), but a 16-bit numbers (uint16), so:
x = [255 67];
y = typecast(uint8(x), 'uint16');
You haven't specified the endianness of your data, nor that of your machine. If the two don't match, you'll have to swapbytes afterward:
truey = swapbytes(y); %if one is big-endian and the other litte-endian