7017
|
1 ## Copyright (C) 1996, 1999, 2000, 2001, 2003, 2005, 2006, 2007 |
|
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 |
3361
|
20 ## -*- texinfo -*- |
4492
|
21 ## @deftypefn {Function File} {} dec2hex (@var{n}, @var{len}) |
3789
|
22 ## Return the hexadecimal string corresponding to the nonnegative |
|
23 ## integer @var{n}. For example, |
3426
|
24 ## |
3361
|
25 ## @example |
|
26 ## dec2hex (2748) |
3789
|
27 ## @result{} "ABC" |
3361
|
28 ## @end example |
3789
|
29 ## |
|
30 ## If @var{n} is a vector, returns a string matrix, one row per value, |
|
31 ## padded with leading zeros to the width of the largest value. |
4492
|
32 ## |
|
33 ## The optional second argument, @var{len}, specifies the minimum |
|
34 ## number of digits in the result. |
5642
|
35 ## @seealso{hex2dec, dec2base, base2dec, bin2dec, dec2bin} |
3361
|
36 ## @end deftypefn |
2311
|
37 |
3791
|
38 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789
|
39 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314
|
40 |
4492
|
41 function retval = dec2hex (n, len) |
2268
|
42 |
4492
|
43 if (nargin == 1) |
|
44 retval = dec2base (n, 16); |
|
45 elseif (nargin == 2) |
|
46 retval = dec2base (n, 16, len); |
3789
|
47 else |
6046
|
48 print_usage (); |
2268
|
49 endif |
2325
|
50 |
2268
|
51 endfunction |