How use "bitget" and "bitset" function?

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?

Risposte (2)

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 il 30 Ago 2019
Modificato: Weslley Eduardo il 30 Ago 2019

0 voti

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 Commento

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)

Accedi per commentare.

Categorie

Scopri di più su MATLAB Coder in Centro assistenza e File Exchange

Prodotti

Release

R2019a

Tag

Richiesto:

il 30 Ago 2019

Commentato:

il 30 Ago 2019

Community Treasure Hunt

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

Start Hunting!

Translated by