![]() |
反向查询表
这是前一个[URL="https://stackoverflow.com/questions/1544456/faster-version-of-dec2bin-function-for-converting-many-elements"]SO问题[/URL]的跟进[URL="https://stackoverflow.com/questions/1544456/faster-version-of-dec2bin-function-for-converting-many-elements"]问题[/URL] 。现在,我将其扩展为8位。我使用Amro的解决方案将位扩展为8位。现在,我想以相反的方式将8位转换回单位。
我只设法实现for循环的反向使用,这在应用程序中花费了很多时间。 有更快的方法吗? [B]回答:[/B] 由于您使用的是我上次建议的解决方案,因此,假设您有一个由这些“位”组成的N×8矩阵,其中每一行代表一个8位二进制数。要以矢量化方式转换为十进制,其操作非常简单: 禄 M = randi([0 1], [5 8]) %# 5 random 8-bit numbers M = 1 0 1 0 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 0 0 1 0 1 1 0禄 d = bin2dec( num2str(M) ) d = 171 110 219 134 150 替代解决方案: d = sum( bsxfun(@times, M, power(2,7:-1:0)), 2) [url=https://stackoverflow.com/questions/2287841]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 05:05。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.