dec2bin

Converts a non-negative integer, matrix or cell array, n, to it's binary equivalent.

Syntax

R = dec2bin(n)

R = dec2bin(n, len)

Inputs

n
Finite, non-negative integer, matrix or cell array of finite, non-negative integers.
Type: cell | mat | int
len (optional)
Optional argument which can specify the minimum length of each element if n is a matrix or a cell array. Valid values are finite, positive integers.
Type: Finite, positive integer

Outputs

R
If n is a matrix or cell array, R, will be a string array with one row for each element. Every element will be the same width as the widest element, with leading zeros padding the value.
Type: matrix | string

Examples

Integer to binary example:
R = dec2bin(97)
R = 1100001
Matrix to binary example:
R = dec2bin([97, 65, 1])
R =
1100001
1000001
0000001
Cell array, with minimum output length specified, to binary example:
R = dec2bin({7, 5, 1}, 8)
R =
00000111
00000101
00000001