How do I use the previous syntax of BITCMP to specify the number of returned in MATLAB (R2013b)?

10 views (last 30 days)
Up to MATLAB (R2012a), the previous syntax of the bit-complement function BITCMP allowed the user to use a second input arguments, in order to specify the number of returned bits. For instance the following command returns a warning:
>> x = 5;
>> N = 4;
>> bitcmp(x,N)
Warning: BITCMP(A,N) will not accept integer valued input N in a future release. Use BITCMP(A,ASSUMEDTYPE)
instead.
ans =
10
Is there a way I can still use the previous syntax?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
As explained in the warning, the previous syntax will be deprecated. The reason behind is that BITCMP, along with other functions such as BITAND, BITOR, BITGET, BITSET, etc. support signed integers as of MATLAB (R2012b).
As such, to avoid the ambiguity in a call such as
>> bitcmp(5,8)
where "8" could be either unsigned or signed integer, an additional input argument, can be passed to these functions to indicate the assumed integer class for input values of type double. For example, bitor(14,240,'uint8') treats 14 and 240 as unsigned 8-bit integers even though they are passed as integers of type double.
Details about this change can be found in the release notes for MATLAB (R2012b).
Nevertheless, a workaround is to create a function "bitcmpOld" defined as follows:
function output = bitcmpOld(x,N)
if nargin < 2
output = bitcmp(x);
else
maxN = 2^N-1; % This is the max number you can represent in 4 bits
fmt = 'uint8'; % You can change uint8 to uint16 or 32
out1 = eval(['bitcmp(',fmt,'(x)',',''',fmt,''')']);
out2 = eval(['bitcmp(',fmt,'(maxN)',',''',fmt,''')']);
output = out1 - out2;
end
end
This function allows both the old and new syntax. You can test and compare the following results:
>> x = 5;
>> N = 4;
>> fprintf('Using bitcmp(x,N)\n')
>> bitcmp(x,N)
Warning: BITCMP(A,N) will not accept integer valued input N in a future release. Use BITCMP(A,ASSUMEDTYPE)
instead.
ans =
10
>> fprintf('Using bitcmpOld(x,N)\n')
>> bitcmpOld(x,N)
ans =
10

More Answers (0)

Tags

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!