Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.4.1 - English

Change language to:
Français - 日本語 - Português - Русский

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

Scilab help >> Elementary Functions > Radix conversions > dec2bin

dec2bin

convert from decimal to binary

Calling Sequence

str=dec2bin(x)
str=dec2bin(x,n)

Arguments

x

matrix of doubles, positive integer values

n

a positive integer

str

a matrix of strings

Description

Given x, a positive (or a vector/matrix 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 column 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 components 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).
// 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)

See Also

  • base2dec — convert from base b to decimal
  • bin2dec — convert from binary to decimal
  • oct2dec — convert from octal to decimal
  • hex2dec — convert from hexadecimal to decimal
  • dec2oct — convert from decimal to octal
  • dec2hex — convert from decimal to hexadecimal
Report an issue
<< dec2base Radix conversions dec2hex >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Apr 02 17:36:21 CEST 2013