フィルターのクリア

ROTL and ROTR for 64 bits

1 回表示 (過去 30 日間)
suzi freunden
suzi freunden 2012 年 5 月 12 日
Hi, is there a Circular left bit shift operator for 64 bits? for exemple I have this number x=9223372036855037954 circular left shift and right shift by 4 bits should give the following results: xr=2882303761517133824 xl=4194344 thanks a lot

回答 (2 件)

Jan
Jan 2012 年 5 月 12 日
a = uint64(9223372036855037954); % Not correct in 2009a!
n = rem(n, 64);
bitor(bitshift(a, -n), bitshift(a, (64-n)))
bitor(bitshift(a, n), bitshift(a, (n-64)))
  3 件のコメント
Jan
Jan 2012 年 5 月 13 日
See: http://www.mathworks.com/matlabcentral/answers/9886-uint64-equivalence
In 2009a, "a=uint64(9223372036855037954)" leads to: a = 9223372036855037951. Unfortunately the number is converted to a DOUBLE at first loosing some bits of precision, and cast to UINT64 afterwards. This behavior has been made consistent in 2010b. The UINT64 support in 2009a is very limited, e.g. operators are not implemented.
Please post your Matlab version.
suzi freunden
suzi freunden 2012 年 5 月 13 日
yes I notice this cast, my matlab version is 2009b....

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


Walter Roberson
Walter Roberson 2012 年 5 月 12 日
No there is not. Extract the N bits at the edge using bitget(), use bitshift() to do the shift, and then bitset() the extra bits into place at the other edge.
  2 件のコメント
suzi freunden
suzi freunden 2012 年 5 月 13 日
thanks a lot but bitget have a maximum less than 2^53
Walter Roberson
Walter Roberson 2012 年 5 月 14 日
bitget() does not have such a restriction in R2009b.
http://www.mathworks.com/help/releases/R2009b/techdoc/ref/bitget.html
However, you may have difficulty constructing an unsigned numeric object with higher-order bits set in R2009b. That is a problem with the MATLAB parser, not with the operation of bitget.

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by