Mercurial > hg > octave-nkf
annotate scripts/strings/dec2hex.m @ 12451:c6c3fdbfede2
untabify configure.ac
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 15 Feb 2011 12:57:03 -0500 |
parents | c792872f8942 |
children | f7cb824dc8c0 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1996-2011 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 |
3361 | 19 ## -*- texinfo -*- |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {} dec2hex (@var{d}, @var{len}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
21 ## Return the hexadecimal string corresponding to the non-negative |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
22 ## integer @var{d}. For example: |
3426 | 23 ## |
3361 | 24 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## @group |
3361 | 26 ## dec2hex (2748) |
3789 | 27 ## @result{} "ABC" |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## @end group |
3361 | 29 ## @end example |
3789 | 30 ## |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
31 ## If @var{d} is a vector, return a string matrix, one row per value, |
3789 | 32 ## padded with leading zeros to the width of the largest value. |
4492 | 33 ## |
34 ## The optional second argument, @var{len}, specifies the minimum | |
35 ## number of digits in the result. | |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
36 ## @seealso{hex2dec, dec2base, dec2bin} |
3361 | 37 ## @end deftypefn |
2311 | 38 |
3791 | 39 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789 | 40 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314 | 41 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
42 function h = dec2hex (d, len) |
2268 | 43 |
4492 | 44 if (nargin == 1) |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
45 h = dec2base (d, 16); |
4492 | 46 elseif (nargin == 2) |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
47 h = dec2base (d, 16, len); |
3789 | 48 else |
6046 | 49 print_usage (); |
2268 | 50 endif |
2325 | 51 |
2268 | 52 endfunction |
7411 | 53 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
54 %!assert(strcmpi (dec2hex (2748), "abc")); |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
55 %!assert(strcmpi (dec2hex (2748, 5), "00abc")); |
7411 | 56 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
57 %% Test input validation |
7411 | 58 %!error dec2hex (); |
59 %!error dec2hex (1, 2, 3); | |
60 |