arun raj
arun raj

Reputation: 11

Bitshift error in Matlab 2016a

if strcmp(mappingtype,'u2') %Uniform 2
  newMax = samples*(samples-1) + 3; 
  for i = 0:2^samples-1
    j = bitset(bitshift(i,1,samples),1,bitget(i,samples));

While trying to run the program, i'm getting the following error in the function.

Error using bitshift ASSUMEDTYPE must be an integer type name.

Upvotes: 0

Views: 1939

Answers (3)

kowshik thopalli
kowshik thopalli

Reputation: 11

I had the same problem. I know that this is a old question, but I am posting here in case someone else has a similar question. This is because Matlab has stopped supporting bitshift operation with three number arguments. so instead of using
bitshift(i,1,samples) use bitand(bitshift(i,1),2^samples-1)

reference- https://www.reddit.com/r/matlab/comments/1ttat5/help_me_with_bitshifting_and_bit_truncation/

Upvotes: 1

PintoUbuntu
PintoUbuntu

Reputation: 41

Unless this is Octave code and not Matlab's. In Octave's bitshift operator, 3 arguments are allowed. I tried this, turns out that j's binary representation is the left rotation of i's binary representation.

Upvotes: 0

Jin
Jin

Reputation: 714

As I commented, just use two arguments for computing i * 2 ^ samples by using bitshift(i, samples)

Or, use bitshift(1, samples) to get 2 ^ samples.

The third argument is for assuming data type and it should be like 'int16' or 'int8', not a variable for computing.

Upvotes: 0

Related Questions