Tom*_*zen 4 matlab binary-data
我有一个 32 位数字 (uint32),其中包含四个数字,如下所示:
以下代码有效,但我想让它更快
Var1=bitshift(fourbytes,-30);
Var2_temp=bitshift(fourbytes,-21);
Var2=bitand(Var2_temp,511);
Var3_temp=bitshift(fourbytes,-12);
Var3=bitand(Var2_temp,511);
Var4=bitand(fourbytes,2^12-1));
Run Code Online (Sandbox Code Playgroud)
例子:
fourbytes = 2149007896;
Run Code Online (Sandbox Code Playgroud)
结果是
Var1=2;
Var2=0;
Var3=372
Var4=536
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的东西
Var1=bin2dec(num2str(bitget(fourbytes,32:-1:31)));
Run Code Online (Sandbox Code Playgroud)
但这和 bi2de 一样慢得令人难以置信
bi2de(bitget(onebyte(1),32:-1:31),'left-msb');
Run Code Online (Sandbox Code Playgroud)
是我用 C 编写这部分的唯一选择,还是我缺少更好的方法?
这可以通过以下方式完成
我没有计时,但它可能比你当前的方法更快。
fourbytes = 2149007896;
var1 = floor(fourbytes/2^30);
var2 = mod(floor(fourbytes/2^21), 2^9);
var3 = mod(floor(fourbytes/2^12), 2^9);
var4 = mod(fourbytes, 2^12);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
118 次 |
| 最近记录: |