필터 지우기
필터 지우기

Alternative to bitshift(A,k,N) as in 2014a , it gives a warning and I would like to avoid using it. But cannot understand alternative suggested.

조회 수: 10 (최근 30일)
I have a binary number
% code
a = uint8(88) , b = dec2bin(a) --> b = 1011000
I would like to just get consecutive 11 without using bitshift(a,-3,2).
As in 2014a it gives following warning: Warning: BITSHIFT(A,K,N) will not accept integer valued input N in a future release. Use BITSHIFT(A,K,ASSUMEDTYPE) instead.
I cannot understand how to use bitshift(A,K,Assumedtype) for this issue.
Any idea how to get away without warning so that I am okay for newer versions.
Thanks for your help. Nirav

채택된 답변

Ashish Gudla
Ashish Gudla 2014년 8월 6일
편집: Ashish Gudla 2014년 8월 6일
If you need to truncate and return only 2 bits after shifting you can "bitand" the result with appropriate number.
for last bit, you use 00000001 --> 1
for last 2 bits, 00000011 --> 3
for last 3 bits, 00000111 --> 7
and so on
For example to get last 2 bits after right shifting 3 bits
bitand( bitshift(a,-3,'uint8') , 3)
  댓글 수: 1
Nirav
Nirav 2014년 8월 7일
편집: Nirav 2014년 8월 7일
Thanks for the answer. Also, it seems to me that there is no added time benefit between
1) bitand(bitshift(a,-3),2^2-1) OR
2) bitand(bitshift(a,-3),'uint8'),2^2-1)
ASSUMEDTYPE is useful only if the input 'a' is of datatype double and NOT integers as for integers ASSUMEDTYPE is same datatype as input.
Thanks, Nirav

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by