<< >> shift in Matlab?
4 次查看(过去 30 天)
显示 更早的评论
In C, bitwise shift can be done using '<<, >>, which are even combined with assignment operators into '<<=, >>=.
In Matlab, I found functions like bitshift, bitsll, bitsra, bitsrl
Which are far less convenient than '<< >> operators. Is there any better way to do shifting.
0 个评论
采纳的回答
Jan
2011-10-14
No. There is no better way in Matlab. There are no >>= or similar inplace operators. This is a principal limitation of Matlab's internal data management.
You can shift by multiplying powers of 2. This has been faster than BITSHIFT in old Matlab releases. But today BITSHIFT is more efficient.
2 个评论
Walter Roberson
2011-10-14
If you use the multiplication approach, be careful about value saturation. When you use an int or uint data type, MATLAB does not simply discard bits that would "fall off the end": instead when it detects that the value would be above the numeric maximum for the data type, it sets the result to the numeric maximum for the datatype.
uint8(129) * uint8(2) does not, for example, become 128*2 + 1*2 with the 128*2 discarded: the result would be uint8(255), the maximum uint8 value.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!