left shift in bits

1 回表示 (過去 30 日間)
ablaze
ablaze 2017 年 2 月 2 日
コメント済み: Walter Roberson 2017 年 2 月 3 日
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 件のコメント
ablaze
ablaze 2017 年 2 月 3 日
circular shift
Walter Roberson
Walter Roberson 2017 年 2 月 3 日
How many bits width?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 2 日
Multiply by 2.
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 3 日
For 4 bits (as your values are small):
shifted = pre_shifted * 2;
mask = shifted >= 16;
shifted(mask) = shifted(mask) - 15;

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by