How use "bitget" and "bitset" function?

6 次查看(过去 30 天)
I don't know how to use these functions, and I need for my work.
i need to capture the bits of each pixel in an image, its possible with matlab and "bitget" and "bitset" functions?

回答(2 个)

Steven Lord
Steven Lord 2019-8-30
I thought the examples on the documentation page were pretty clear about how to use the functionality. But now that I take a closer look, those examples operate on scalar A inputs. You can specify a non-scalar array for A so long as the bit input is a scalar (in which case you get that bit of each element in A) or an array of the same size (in which case element N of the output is the bit specified by element N of the bit input of element N of the A input.
%% Sample data
M = magic(5)
%% Scalar case
isOdd = bitget(M, 1)
%% Array case
ind = gallery('circul', 1:5)
B = bitget(M, ind)
% Check with an arbitrarily selected element of M and ind
isequal(B(3, 2), bitget(M(3, 2), ind(3, 2)))
The A, bit, and assumedtype inputs to the bitset function serve the same purposes as those inputs to the bitget function. The V input to bitset is specific to bitset and can be either scalar or the same size as A and/or bit.

Weslley Eduardo
Weslley Eduardo 2019-8-30
编辑:Weslley Eduardo 2019-8-30
So if i declare "test = bitget(im2, 2);", where 'im2' is a image, I will get 2 bits from im2?
And thanks so much for your answer!
  1 个评论
Steven Lord
Steven Lord 2019-8-30
You will get the bit in position 2. So if im2 was 5, which is 101 in binary, that would give you 0. If you asked for bitget(5, 3) you get 1 (since 5 is 1*2^2+0*2^1+1*2^0)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by