view scripts/strings/dec2hex.m @ 27981:7f1cec12c240

maint: Remove simple "Adapted-By:" lines from code base. * __ftp__.cc, urlwrite.cc, lin2mu.m, mu2lin.m, bincoeff.m, common_size.m, nextpow2.m, shift.m, xor.m, griddata.m, colormap.m, gray.m, gray2ind.m, image.m, imagesc.m, imshow.m, ind2gray.m, ind2rgb.m, ocean.m, rgb2ind.m, findstr.m, commutation_matrix.m, cross.m, gls.m, isdefinite.m, ishermitian.m, issymmetric.m, null.m, ols.m, orth.m, qzhess.m, vech.m, orderfields.m, untar.m, unzip.m, orient.m, __pltopt__.m, __gnuplot_print__.m, subplot.m, compan.m, conv.m, deconv.m, poly.m, polyder.m, polyfit.m, polyint.m, polyreduce.m, polyval.m, polyvalm.m, residue.m, roots.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, ifftshift.m, beta.m, lcm.m, pow2.m, corr.m, kurtosis.m, skewness.m, base2dec.m, bin2dec.m, blanks.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, hex2dec.m, index.m, rindex.m, substr.m, calendar.m, datestr.m, datevec.m, eomday.m, now.m, weekday.m: Remove simple "Adapted-By:" lines from code base.
author Rik <rik@octave.org>
date Tue, 21 Jan 2020 13:15:15 -0800
parents bd51beb6205e
children 9f9ac219896d
line wrap: on
line source

########################################################################
##
## Copyright (C) 1996-2020 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################

## -*- texinfo -*-
## @deftypefn {} {} dec2hex (@var{d}, @var{len})
## Return the hexadecimal string corresponding to the non-negative integer
## @var{d}.
##
## For example:
##
## @example
## @group
## dec2hex (2748)
##      @result{} "ABC"
## @end group
## @end example
##
## If @var{d} is a matrix or cell array, return a string matrix with one row
## per element in @var{d}, padded with leading zeros to the width of the
## largest value.
##
## The optional second argument, @var{len}, specifies the minimum number of
## digits in the result.
## @seealso{hex2dec, dec2base, dec2bin}
## @end deftypefn

## Author: Daniel Calvelo <dcalvelo@yahoo.com>

function h = dec2hex (d, len)

  if (nargin == 1)
    h = dec2base (d, 16);
  elseif (nargin == 2)
    h = dec2base (d, 16, len);
  else
    print_usage ();
  endif

endfunction


%!assert (dec2hex (2748), "ABC")
%!assert (dec2hex (2748, 5), "00ABC")
%!assert (dec2hex ({2748, 2746}), ["ABC"; "ABA"])

## Test input validation
%!error dec2hex ()
%!error dec2hex (1, 2, 3)