10-22-2007 03:15 PM
>>bitshift(0,1)I expected 0.
ans =
2
>>bitget(0, 1:3)I expected 0 0 0.
ans =
1 0 0
10-22-2007 04:39 PM
10-22-2007 04:44 PM
10-22-2007 07:43 PM
DrLock, altenbach,
The help file entry for bitshift does specify that the first argument should be a "positive integer" -- making the output for any other input undefined. However I agree with you both that this is not the way it should behave and have sent it to the developers for them to look at. This was reported to R&D (ID# 4ELI7NVQ) for further investigation.
One possible workaround would be to simply check for a zero input with a snippet of code such as:
if a==0
ans=0
else
ans=bitshift(a,1)
end
I hope this helps.
Regards,
Simon H
Applications Engineer
National Instruments
http://www.ni.com/support/
from the LabVIEW Helpd = bitshift(a, b, c)
Description
Performs a bitwise shift on the input elements. For example, if a = 9 (1001), bitshift(a, 1) = 18 (10010) and bitshift(a, 1, 4) = 2 (0010).
Inputs
Name Description a Specifies a scalar, vector, or matrix of positive integers. All elements of a must be less than bitmax. b Determines the shift sizes. Shifting a by b bits is equivalent to multiplying a by 2^b and then rounding to the nearest integer. b is a scalar, vector, or matrix of integers. b is the same size as a unless a or b is a scalar. c Specifies the number of valid bits for each of the shifted integers. If the shifted integers exceed c bits, LabVIEW ignores the overflow. c is a matrix of integers. The default is 53.
10-22-2007 07:50 PM
Hmm... so the labview help is more restrictive here for no good reason.
I was consulting the matlab help, which is more general:
"C = bitshift(A, k) returns the value of A shifted by k bits. Input argument A must be an unsigned integer or an array of unsigned integers."
Clearly, the function should be defined the same in both environments. 🙂