1######################################################################## 2## 3## Copyright (C) 1996-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {} dec2hex (@var{d}, @var{len}) 28## Return the hexadecimal string corresponding to the non-negative integer 29## @var{d}. 30## 31## For example: 32## 33## @example 34## @group 35## dec2hex (2748) 36## @result{} "ABC" 37## @end group 38## @end example 39## 40## If @var{d} is a matrix or cell array, return a string matrix with one row 41## per element in @var{d}, padded with leading zeros to the width of the 42## largest value. 43## 44## The optional second argument, @var{len}, specifies the minimum number of 45## digits in the result. 46## @seealso{hex2dec, dec2base, dec2bin} 47## @end deftypefn 48 49function h = dec2hex (d, len) 50 51 if (nargin == 1) 52 h = dec2base (d, 16); 53 elseif (nargin == 2) 54 h = dec2base (d, 16, len); 55 else 56 print_usage (); 57 endif 58 59endfunction 60 61 62%!assert (dec2hex (2748), "ABC") 63%!assert (dec2hex (2748, 5), "00ABC") 64%!assert (dec2hex ({2748, 2746}), ["ABC"; "ABA"]) 65 66## Test input validation 67%!error dec2hex () 68%!error dec2hex (1, 2, 3) 69