Question

In MATLAB R2011b it is not possible to process bit-and operation if any of numbers is negative. In Java it would be something like: -25 & 15 = 7. How is it possible to get something similar in MATLAB? Tried to convert to uint32 before operation, but uint32(-25) = 0 in MATLAB.

Was it helpful?

Solution

You can use the bitand operation:

intout = bitand(-25, 7, 'int32')

On R2011b, -25 is bit-wise equivalent to (2^32)-25 if you consider uint32. So you can try:

intout = int32((2^32 - 25) & 7)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top