How use "bitget" and "bitset" function?

조회 수: 6 (최근 30일)
Weslley Eduardo
Weslley Eduardo 2019년 8월 30일
댓글: Steven Lord 2019년 8월 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