how to rotate right ?

조회 수: 1 (최근 30일)
yogya
yogya 2014년 10월 31일
댓글: Jan 2014년 11월 1일
If my binary data is 1001011011110100 then how can i rotate right the stream by 4 bits with out converting it from binary to any other data type or number system.
  댓글 수: 3
Star Strider
Star Strider 2014년 11월 1일
I answered it yesterday (circshift link + example) then OP posted a later question using my answer to this one without accepting it, so I deleted my answer.
Jan
Jan 2014년 11월 1일
@yogya: Please explain the type of the data. It is not efficient to guess, how your "binary data" are represented currently, when you explicitly want to avoid a conversion.

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

답변 (1개)

Harry
Harry 2014년 11월 1일
편집: Harry 2014년 11월 1일
If your binary data is stored in a string, try this:
x = '1001011011110100';
x_shifted = circshift(x,[0,4]);
Otherwise, if you have raw binary data (for example, stored in unsigned 16-bit integers), then try this:
msbs = bitshift(n,-4, 'uint16');
lsbs = bitand(n,2^4-1, 'uint16');
x_shifted = bitor(bitshift(lsbs, Nbits-4, 'uint16'), msbs, 'uint16');

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by