How use "bitget" and "bitset" function?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (2)
Steven Lord
le 30 Août 2019
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.
0 commentaires
Weslley Eduardo
le 30 Août 2019
Modifié(e) : Weslley Eduardo
le 30 Août 2019
1 commentaire
Steven Lord
le 30 Août 2019
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)
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!