left shift in bits

hello, i want to perform left shift by 1 bit in this code for left_1 and right_1
% 1 2 3 4 5 6 7 8 9 10
key=[1 0 1 0 0 0 0 0 1 0]
IP=[3 5 2 7 4 10 1 9 8 6]
left=key(IP(1:5))
left_1=left
right=key(IP(6:10))
right_1=right

3 Commenti

James Tursa
James Tursa il 2 Feb 2017
What kind of shift? Circular shift? Fall-off-the-end shift? Shift bits to/from "left" variable and "right" variables?
ablaze
ablaze il 3 Feb 2017
circular shift
Walter Roberson
Walter Roberson il 3 Feb 2017
How many bits width?

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 2 Feb 2017

0 voti

Multiply by 2.

1 Commento

For 4 bits (as your values are small):
shifted = pre_shifted * 2;
mask = shifted >= 16;
shifted(mask) = shifted(mask) - 15;

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 2 Feb 2017

Community Treasure Hunt

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

Start Hunting!

Translated by