1 ## Copyright (C) 1996-2012 Daniel Calvelo
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} dec2hex (@var{d}, @var{len})
21 ## Return the hexadecimal string corresponding to the non-negative
22 ## integer @var{d}. For example:
31 ## If @var{d} is a matrix or cell array, return a string matrix with one
32 ## row per element in @var{d}, padded with leading zeros to the width of
35 ## The optional second argument, @var{len}, specifies the minimum
36 ## number of digits in the result.
37 ## @seealso{hex2dec, dec2base, dec2bin}
40 ## Author: Daniel Calvelo <dcalvelo@yahoo.com>
41 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
43 function h = dec2hex (d, len)
48 h = dec2base (d, 16, len);
56 %!assert(dec2hex (2748), "ABC");
57 %!assert(dec2hex (2748, 5), "00ABC");
58 %!assert(dec2hex ({2748, 2746}), ["ABC"; "ABA"]);
60 %% Test input validation
62 %!error dec2hex (1, 2, 3);