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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
2268
|
19 |
3446
|
20 ## -*- texinfo -*- |
3789
|
21 ## @deftypefn {Function File} {} hex2dec (@var{s}) |
|
22 ## Return the decimal number corresponding to the binary number stored |
|
23 ## in the string @var{s}. For example, |
2311
|
24 ## |
3446
|
25 ## @example |
3789
|
26 ## hex2dec ("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. |
3446
|
32 ## @end deftypefn |
3789
|
33 ## |
|
34 ## @seealso{dec2hex, base2dec, dec2base, bin2dec, dec2bin} |
2311
|
35 |
3791
|
36 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789
|
37 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314
|
38 |
3789
|
39 function d = bin2dec (h) |
2268
|
40 |
|
41 if (nargin != 1) |
3789
|
42 usage ("bin2dec (b)"); |
2268
|
43 else |
3789
|
44 d = base2dec (h, 2); |
2268
|
45 endif |
2325
|
46 |
2268
|
47 endfunction |