Mercurial > hg > octave-nkf
annotate scripts/strings/bin2dec.m @ 10821:693e22af08ae
Grammarcheck documentation of m-files
Add newlines between @item fields for readability.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 26 Jul 2010 21:25:36 -0700 |
parents | 16f53d29049f |
children | 7e8ce65f73cf |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 1996, 2000, 2001, 2005, 2006, 2007, 2008, 2009 |
2 ## Daniel Calvelo | |
2325 | 3 ## |
2313 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
23 ## in the string @var{s}. For example: |
2311 | 24 ## |
3446 | 25 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## @group |
5666 | 27 ## bin2dec ("1110") |
3446 | 28 ## @result{} 14 |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## @end group |
3446 | 30 ## @end example |
3789 | 31 ## |
32 ## If @var{s} is a string matrix, returns a column vector of converted | |
33 ## numbers, one per row of @var{s}. Invalid rows evaluate to NaN. | |
5666 | 34 ## @seealso{dec2hex, base2dec, dec2base, hex2dec, dec2bin} |
3446 | 35 ## @end deftypefn |
2311 | 36 |
3791 | 37 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789 | 38 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314 | 39 |
3789 | 40 function d = bin2dec (h) |
2268 | 41 |
5924 | 42 if (nargin == 1 && ischar (h)) |
43 n = rows (h); | |
44 d = zeros (n, 1); | |
45 for i = 1:n | |
46 s = h(i,:); | |
47 s = s(! isspace (s)); | |
48 d(i) = base2dec (s, 2); | |
49 endfor | |
2268 | 50 else |
5924 | 51 print_usage (); |
2268 | 52 endif |
2325 | 53 |
2268 | 54 endfunction |
7411 | 55 |
56 %!assert(bin2dec ("1110") == 14); | |
57 | |
58 %!error bin2dec (); | |
59 | |
60 %!error bin2dec ("str", 1); | |
61 |