How use "bitget" and "bitset" function?

6 visualizaciones (últimos 30 días)
Weslley Eduardo
Weslley Eduardo el 30 de Ag. de 2019
Comentada: Steven Lord el 30 de Ag. de 2019
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?

Respuestas (2)

Steven Lord
Steven Lord el 30 de Ag. de 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.

Weslley Eduardo
Weslley Eduardo el 30 de Ag. de 2019
Editada: Weslley Eduardo el 30 de Ag. de 2019
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 comentario
Steven Lord
Steven Lord el 30 de Ag. de 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)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by