b = de2bi(d) converts a
nonnegative decimal integer d to a binary row vector. If
d is a vector, the output b is a matrix in
which each row is the binary form of the corresponding element in
d.
This example shows how to convert decimals to binary numbers in their base-2 equivalents.
d_array = [1 2 3 4];
Convert the decimal array to binary by using the de2bi function. Specify that the most significant digit is the leftmost element and set the number of desired columns to 5. The output becomes a 4-by-5 matrix where each row corresponds to a decimal value from the input. Because the largest decimal value in d_array can be expressed in 3 columns, the de2bi pads the matrix with two extra zero columns at the specified most-significant bit side. If you specify too few columns, the conversion will fail.