>  Docs Center  >  Libraries  >  JHU/APL/S1R  >  BASECON






      Convert an integer number from one base to another.


Calling Sequence

      out = basecon(in)


      in = input as a text string or numeric value. in
          May be an array.

Keyword Parameters


        FROM=n1 Original number base (def=10).
          From 2 to 36.
        TO=n2 Resulting number base (def=10).
          From 2 to 36.
          If n2 is 2, 8, or 16 then the native IDL formatting
          will be used. This can handle any integer type
          including negative LL values.
          If the keyword /NOIDL is given this routine will use
          the same method as for the other bases but will be
          limited to the value given below and no negative LL.
        DIGITS=n Minimum number of digits in output.
          If result has fewer then 0s are placed on left.
          A default number of digits is set for base 2, 8, or 16.
          To over-ride this default set DIGITS=0.
        GROUP=g Number of digits to group together (def=all).
          Spaces will be placed between groups. Useful for
          showing bytes or words for example.
        /BITS Convert the input to a bits display. Assumes
            base 10 input,base 2 output. 0 show as . and 1 as |.
            Each value is grouped into 8 bit bytes and have
            extra trailing spaces added for display.
        ERROR=err error flag:
          0 = ok
          1 = input digit not 0-9 or A-Z.
          2 = FROM base not in the range 2-36.
          3 = TO base not in the range 2-36.
          4 = input digit too big for FROM base.
          5 = input number too big to handle.
          6 = Data type not supported.


      out = converted number as a text string. out
        If an error occurs a null string is returned.
        Will have the same dimensions as the input.

Common Blocks


      Notes: maximum number base is 36. Example:
        out = basecon('1010',from=2,to=16) gives out='A'.
        May give an array of input values.
        Can handle negative 16 and 32 bit integers.
        May group digits in an input string.
        Maximum positive integer that can be handled is
        9223372036854775807 = 2LL^63-1

Modification History

      R. Sterner, 5 Mar, 1993
      R. Sterner, 30 Sep, 1993 --- Added DIGITS keyword.
      R. Sterner, 1999 Jun 03 --- Added GROUP keyword.
      R. Sterner, 2002 Jun 13 --- Extended range by using LONG64.
      R. Sterner, 2005 Nov 21 --- Supported negative integers.
      R. Sterner, 2005 Nov 21 --- Allowed spaces in input string.
      R. Sterner, 2008 Dec 30 --- Fixed problem with string input.
      R. Sterner, 2009 Nov 17 --- Fixed loop limit.
      R. Sterner, 2010 Apr 30 --- Converted arrays from () to [].
      R. Sterner, 2011 Jun 27 --- Allowed byte type.
      R. Sterner, 2011 Jun 27 --- Fixed to handle ULL type better (< limit).
      R. Sterner, 2011 Jun 28 --- Added IDL format code handling for to=2,8,
      or 16. Can now do any integer including LONG64 both positive
      and negative.
      R. Sterner, 2011 Jun 30 --- Added keyword /BITS.
      R. Sterner, 2011 Jul 01 --- Output reformed to match input shape.
  Copyright (C) 1993, Johns Hopkins University/Applied Physics Laboratory
  This software may be used, copied, or redistributed as long as it is not
  sold and this copyright notice is reproduced on each copy made. This
  routine is provided as is without any express or implied warranties
  whatsoever. Other limitations apply as described in the file disclaimer.txt.

© 2020 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us