3789
|
1 ## Copyright (C) 2000 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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
2268
|
19 |
3446
|
20 ## -*- texinfo -*- |
5666
|
21 ## @deftypefn {Function File} {} bin2dec (@var{s}) |
3789
|
22 ## Return the decimal number corresponding to the binary number stored |
|
23 ## in the string @var{s}. For example, |
2311
|
24 ## |
3446
|
25 ## @example |
5666
|
26 ## bin2dec ("1110") |
3446
|
27 ## @result{} 14 |
|
28 ## @end example |
3789
|
29 ## |
|
30 ## If @var{s} is a string matrix, returns a column vector of converted |
|
31 ## numbers, one per row of @var{s}. Invalid rows evaluate to NaN. |
5666
|
32 ## @seealso{dec2hex, base2dec, dec2base, hex2dec, dec2bin} |
3446
|
33 ## @end deftypefn |
2311
|
34 |
3791
|
35 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789
|
36 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314
|
37 |
3789
|
38 function d = bin2dec (h) |
2268
|
39 |
|
40 if (nargin != 1) |
3789
|
41 usage ("bin2dec (b)"); |
2268
|
42 else |
3789
|
43 d = base2dec (h, 2); |
2268
|
44 endif |
2325
|
45 |
2268
|
46 endfunction |