3789
|
1 ## Copyright (C) 2001 Daniel Calvelo |
2325
|
2 ## |
2313
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
2268
|
19 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} dec2bin (@var{n}) |
|
22 ## Return a binary number corresponding the nonnegative decimal number |
|
23 ## @var{n}, as a string of ones and zeros. For example, |
3426
|
24 ## |
3361
|
25 ## @example |
|
26 ## dec2bin (14) |
|
27 ## @result{} "1110" |
|
28 ## @end example |
3789
|
29 ## |
|
30 ## If @var{n} is a vector, returns a string matrix, one row per value, |
|
31 ## padded with leading zeros to the width of the largest value. |
3361
|
32 ## @end deftypefn |
3789
|
33 ## |
|
34 ## @seealso{bin2dec, dec2base, base2dec, hex2dec, dec2hex} |
2268
|
35 |
3791
|
36 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789
|
37 ## 2001-02-02 Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314
|
38 |
3789
|
39 function h = dec2bin (d) |
2268
|
40 |
|
41 if (nargin != 1) |
3789
|
42 usage ("dec2bin (b)"); |
|
43 else |
|
44 h = dec2base (d, 2); |
2268
|
45 endif |
|
46 |
|
47 endfunction |