Main Content


Convert symbolic integer in decimal to binary representation



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

If d is a matrix or multidimensional array of symbolic integers 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 = 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 = 


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

Integers in decimal representation, specified as a symbolic number, vector, matrix, or array.

In R2023a: d can include negative integers. The function converts negative integers using their two's complement binary values.

Example: sym([2 4])

Number of bits, specified as a scalar positive integer.

Example: 8

Version History

Introduced in R2019a

See Also

External Websites