MATLAB: Dec2bin is adding inappropriate 0s to negative numbers when numBits is specified conversiondec2bin e.g. dec2bin(-23, 10) produces '0011101001', but it should produce '1111101001'. Best Answer Report to tech support. I think it looks like a bug.From "doc dec2bin" in R2020aStarting in R2020a, the dec2bin function converts negative numbers using their two's complement binary values.versionans = '9.8.0.1376261 (R2020a) Update 2'dec2bin(-23)ans = '11101001'dec2bin(-23,8)ans = '11101001'dec2bin(-23,9)ans = '011101001' Related SolutionsMATLAB: Bit setting a binary number a = dec2bin(3124)a(end - (5:-1:0)) = '100000' MATLAB: Trouble with converting dec2bin x=[1 3 5 7];outx=dec2bin(x) Related QuestionError while using dec2bin() : too many input argumentsOne’s and two’s complement
Best Answer