MATLAB: Converting base 10 to base 2, dec2base help

baseconversionmatrix

So I am writing a script to convert a number from base 10 to base 2. I have written my own script, but I had trouble using dec2base. The function does not seem to work when I write something like
(i = dec2base(4, 2); and also fprintf('%g', i))
It outputs 494848. However, if I simply write dec2base(4, 2) without a semicolon the operation works, but the format is wrong.

Best Answer

X = dec2base(4,2)
whos X % X is a character array!
fprintf('%g', X) % prints out ascii codes of the string!, Similar to ...
fprintf('%g', 'hello')
fprintf('%s', X) % use %s as a format string for character arrays