how to rotate right ?

2 views (last 30 days)
yogya on 31 Oct 2014
Commented: Jan on 1 Nov 2014
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.
Jan on 1 Nov 2014
@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.

Sign in to comment.

Answers (1)

Harry on 1 Nov 2014
Edited: Harry on 1 Nov 2014
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');


Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!