Mercurial > hg > octave-nkf
annotate scripts/strings/bin2dec.m @ 9209:923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
spellchecked all .txi and .texi files.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 17 May 2009 12:18:06 -0700 |
parents | 1bf0ce0930be |
children | 16f53d29049f |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 2000, 2001, 2005, 2006, 2007, 2008 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2268 | 18 |
3446 | 19 ## -*- texinfo -*- |
5666 | 20 ## @deftypefn {Function File} {} bin2dec (@var{s}) |
3789 | 21 ## Return the decimal number corresponding to the binary number stored |
22 ## in the string @var{s}. For example, | |
2311 | 23 ## |
3446 | 24 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## @group |
5666 | 26 ## bin2dec ("1110") |
3446 | 27 ## @result{} 14 |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## @end group |
3446 | 29 ## @end example |
3789 | 30 ## |
31 ## If @var{s} is a string matrix, returns a column vector of converted | |
32 ## numbers, one per row of @var{s}. Invalid rows evaluate to NaN. | |
5666 | 33 ## @seealso{dec2hex, base2dec, dec2base, hex2dec, dec2bin} |
3446 | 34 ## @end deftypefn |
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 |
5924 | 41 if (nargin == 1 && ischar (h)) |
42 n = rows (h); | |
43 d = zeros (n, 1); | |
44 for i = 1:n | |
45 s = h(i,:); | |
46 s = s(! isspace (s)); | |
47 d(i) = base2dec (s, 2); | |
48 endfor | |
2268 | 49 else |
5924 | 50 print_usage (); |
2268 | 51 endif |
2325 | 52 |
2268 | 53 endfunction |
7411 | 54 |
55 %!assert(bin2dec ("1110") == 14); | |
56 | |
57 %!error bin2dec (); | |
58 | |
59 %!error bin2dec ("str", 1); | |
60 |