MATLAB: Split decimal number which consists of 2 binary numbers

binarydecimal

I have an array of decimal numbers with numbers like for example 2108784171. these numbers consist of 2 binary numbers from which the first 1:16 bits belong to a decimal number and the 17:32 bits belong to another decimal number. How can I split the decimal number array without first going to binary with dec2bin and then splitting it manually with:
firstDecimalNumber = bin2dec(binNumber(:,17:end));
secondDecimalNumber = bin2dec(binNumber(:,1:16));
I want the two decimal numbers but converting it twice, from decimal to binary and from binary to decimal takes too much time as this calculation is performed in a time sensitive loop. Is there a way to have a faster splitting method?

Best Answer

A = 0x01020304u32
A = uint32 16909060
A16 = typecast(A, 'uint16')
A16 = 1×2
772 258
dec2bin(A,32)
ans = '00000001000000100000001100000100'
dec2bin(A16,16)
ans = 2x16 char array
'0000001100000100' '0000000100000010'
Notice that A16(1) corresponds to 0x0304 and A16(2) corresponds to 0x0102 .
This is not a bug: this is a disagreement about what it means to look at the "first" 16 bits of a number. Do you mean the first in memory? Or do you mean starting the numbering from the Most Significant Bit and increasing the count as you get less significant? Or do you mean starting the number from the Least Significant Bit and increasing the count as you get more significant?