File Exchange

## Decimal to Binary Conversion

version 1.0.0.0 (507 Bytes) by
Decimal to Binary Converter up to 5 bits

Updated 17 Feb 2015

Decimal Number N = 0 to 32-1, i.e., 0 to \$2^5 -1\$
After reaching the N value to 32 the conversion resets and takes from 0 -
31 again Example if you give 33 then it takes as 33-32 = 1.

### Cite As

Shravankumar P (2021). Decimal to Binary Conversion (https://www.mathworks.com/matlabcentral/fileexchange/49735-decimal-to-binary-conversion), MATLAB Central File Exchange. Retrieved .

John D'Errico

This seems silly. If you want a function that does exactly what this does, then just use dec2bin. It is far more flexible, and far more capable than this poor code.

Note that the code here is limited to inputs from 0 to 31. God knows why anyone would want something so trivial. But it does.

dec2bin(0:31,5)
ans =
32×5 char array
'00000'
'00001'
'00010'
'00011'
'00100'
'00101'
'00110'
'00111'
'01000'
'01001'
'01010'
'01011'
'01100'
'01101'
'01110'
'01111'
'10000'
'10001'
'10010'
'10011'
'10100'
'10101'
'10110'
'10111'
'11000'
'11001'
'11010'
'11011'
'11100'
'11101'
'11110'
'11111'

If you want code that returns a numeric vector, then subtract off '0', like this:

dec2bin(12,5) - '0'
ans =
0 1 1 0 0

But don't waste your time to download this code. dec2bin already exists in every copy of MATLAB, and it has existed probably for more years than this author of this code has been on the earth.

##### MATLAB Release Compatibility
Created with R2013a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux