Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Change language to: English - Português - 日本語

Please note that the recommended version of Scilab is 6.1.1. This page might be outdated.
See the recommended documentation of this function

# dec2bin

binary representation

### Calling Sequence

`[str]=dec2bin(x[,n])`

### Arguments

x

scalar/vector/matrix of positives integers

n

a positive integer

str

a string or a vector of string

### Description

Given `x`, a positive (or a vector/matix of integers) integer, this function returns a string (or a column vector of strings) which is the binary representation of `x.`If dimension of `x` is superior than 1 then each component of the colums vector `str` is the binary representation of the `x` components (i.e `str(i)` is the binary representation of `x(i)`). If the components length of `str` is less than `n` ( i.e length str(i) < n ), then add to `str` components the characters '0' on the left in order to have componants length equal to `n.`

### Examples

```// example 1 :
x=86;
str=dec2bin(x)

// example 2 :
// the binary representation of 86 is: '1010110'
// its length is 7(less than n), so we add to str, 8 times the character '0'  (on the left)
x=86;n=15;
str=dec2bin(x,n)

// example 3 :
x=[12;45;135]
z=dec2bin(x)```