Main Content

dec2bin

Convert symbolic integer in decimal to binary representation

Description

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.

example

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

example

Examples

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 = 
'1000000000000000000000000000000000000000000000000000000000000'

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

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

(641235411)

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
    '1000000'
    '0110110'
    '1111011'
    '0001011'

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

str = dec2bin(d,8)
str = 4x8 char array
    '01000000'
    '00110110'
    '01111011'
    '00001011'

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