Cody

Problem 44971. Convert base 10 to base x (2-16)

Solution 2023805

Submitted on 16 Nov 2019
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   Fail
dec = [12345.12345,9876.9876]; x = 16; y_correct={'3039.1f9a6b50b','2694.fcd35a8588'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test1 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

2   Fail
dec = [12345.12345,9876.9876]; x = 7; y_correct={'50664.0602255245326442','40536.6625141031624663'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test2 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

3   Fail
dec= [9626.150562201365,389979.4884571975,981037227081.0962,15.15348748187026,2951227.338373619,409,667123.807,30421.507,7285.4,38.59]; x=2; y_correct={'10010110011010.0010011010001011','1011111001101011011.0111110100001011','1110010001101010011000000001110001001001.00011000101','1111.001001110100101','1011010000100000111011.0101011010011111','110011001','10100010110111110011.1100111010010111','111011011010101.100000011100101','1110001110101.011001100110011','100110.100101110000101'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test3 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

4   Fail

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test4 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

5   Fail
dec= [9626.150562201365,389979.4884571975,981037227081.0962,15.15348748187026,2951227.338373619,409,667123.807,30421.507,7285.4,38.59]; x=12; y_correct={'56a2.1982083a8431a88a','169823.5a407946253a442','13a16b470949.11a276','13.1a12871b92951307','ba3a77.40886226776a669','2a1','282097.9825b510827439','15731.610119a7a57a6104','4271.4972497249724972','32.70b62a68781b0591'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test5 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

6   Fail
dec=0.173; x=11; y_correct={'0.19a2990645a78076'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test6 (line 4) assert(isequal(dec2basex(dec,x),y_correct))

7   Fail
dec=0; x=3; y_correct={'0'}; assert(isequal(dec2basex(dec,x),y_correct))

base = 0×0 empty cell array

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in dec2basex (line 3) base(end+1) = num2str(dec2base(x,dec)) Error in Test7 (line 4) assert(isequal(dec2basex(dec,x),y_correct))