Convert decimal number to character vector representing binary number



str = dec2bin(d) returns the binary representation of symbolic number d as a character vector. d must be a nonnegative integer.

If d is a matrix or multidimensional array of symbolic numbers with N elements, dec2bin returns a character array with N rows. Each row of the output str corresponds to an element of d accessed with linear indexing.


str = dec2bin(d,n) returns a binary representation with at least n bits.


collapse all

Define a large integer 260 as a symbolic number.

d = sym(2)^60
d = 1152921504606846976sym('1152921504606846976')

Convert the decimal number to binary representation.

str = dec2bin(d)
str = 

Create a 2-by-2 symbolic matrix that contains integers in decimal representation.

d = [sym(2)^6 123; 54 11]
d = 

(641235411)[sym(64), sym(123); sym(54), sym(11)]

Convert the integers to binary representation using dec2bin. dec2bin returns 4 rows of character vectors. Each row contains a 7-digit binary number.

str = dec2bin(d)
str = 4x7 char array

Return a binary representation with at least 8 digits by specifying the number of digits.

str = dec2bin(d,8)
str = 4x8 char array

Input Arguments

collapse all

Decimal number, specified as a symbolic number, vector, matrix, or array. d must be a nonnegative integer.

Example: sym([2 4])

Number of bits, specified as a scalar positive integer.

Example: 8

See Also

Introduced in R2019a