Cody

Solution 1700929

Submitted on 31 Dec 2018 by William
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = [0, -1, 0.5, 2.25, 10.125, -10.5]; s = {'0', '-1', '0.1', '10.01', '1010.001', '-1010.1'}; for n=1:length(x); assert(strcmpi(s{n}, float2base(x(n), 2))); end

2   Pass
x = [0, 1, 0.5, 2.25, 10.125]; s = {'0', '1', '0.8', '2.4', 'a.2'}; for n=1:length(x); assert(strcmpi(s{n}, float2base(x(n), 16))); end

3   Pass
% only checking 6 digits after period x = 3.14; s = {'11.0010001111','3.10753412172','3.23d70a3d70a'}; bases = [2,8,16]; for n=1:length(bases) assert(strncmpi(s{n}, float2base(x, bases(n)), 8)); end