フィルターのクリア

Speeding bitand / bitshift and type conversion

4 ビュー (過去 30 日間)
C R
C R 2020 年 3 月 9 日
コメント済み: C R 2020 年 3 月 10 日
We have a uint32 data word that is made of two uint16 variables, the first 16 bits is variable #1, the second 16 bits is variable #2. To convert, we are using bitand and type casting:
% Take 32-bit DataWord, convert into two 16-bit variables:
Var1 = uint16(bitshift(bitand(DataWord1,uint32(4294901760)),-16)); % 4294901760 = 0b11111111111111110000000000000000
Var2 = uint16(bitand(DataWord1,uint32(65535))); % 65535 = 0b00000000000000001111111111111111
We do this on an incoming data stream, and unfortunatley, our code above is too slow.
Originally we were using bitget, but it returns a row vector of bits, so getting that row vector into a single uint16 variable was even slower.
Thanks for any help to speed up the above.

回答 (1 件)

James Tursa
James Tursa 2020 年 3 月 9 日
編集済み: James Tursa 2020 年 3 月 9 日
Try this:
DataWord16 = typecast(DataWord1,'uint16'); % shared data copy for later versions of MATLAB
Var1 = DataWord16(1:2:end);
Var2 = DataWord16(2:2:end);
  3 件のコメント
James Tursa
James Tursa 2020 年 3 月 9 日
Good point.
C R
C R 2020 年 3 月 10 日
For the data set I am working on this really sped things up. Thanks for the help!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by