| int2hx |
|
Table of contents
Procedure
INT2HX ( Integer to signed hexadecimal string )
SUBROUTINE INT2HX ( NUMBER, STRING, LENGTH )
Abstract
Convert an integer to an equivalent signed hexadecimal string.
Required_Reading
None.
Keywords
ALPHANUMERIC
CONVERSION
Declarations
IMPLICIT NONE
INTEGER NUMBER
CHARACTER*(*) STRING
INTEGER LENGTH
Brief_I/O
VARIABLE I/O DESCRIPTION
-------- --- --------------------------------------------------
NUMBER I Integer to be converted.
STRING O Equivalent hexadecimal string, left justified.
LENGTH O The length of the hexadecimal string produced.
Detailed_Input
NUMBER is the integer to be converted.
Detailed_Output
STRING is the signed hexadecimal string representing the integer
NUMBER.
The following table describes the character set used
to represent the hexadecimal digits and their
corresponding values.
Character Value Character Value
--------- ----- --------- -----
'0' 0 '8' 8
'1' 1 '9' 9
'2' 2 'A' 10
'3' 3 'B' 11
'4' 4 'C' 12
'5' 5 'D' 13
'6' 6 'E' 14
'7' 7 'F' 15
In order to obtain the entire signed hexadecimal number,
the output character string should be at least N
characters long, where
# of bits per integer + 3
N = 1 + ---------------------------- .
4
There should be 1 character position for the sign, and
one character position for each hexadecimal digit that
could be produced from any integer which can be
represented by a particular computer system.
The following table contains minimum output string
lengths necessary to obtain the complete hexadecimal
string for various integer sizes.
Integer size in bits Minimum output length
-------------------- ---------------------
8 3
16 5
32 9
36 (really,it exists) 10
64 17
etc.
The hexadecimal character string produced by this
routine will be left justified and consist of a
contiguous sequence of hexadecimal digits, or in the
case of a negative number, a contiguous sequence of
hexadecimal digits immediately preceded by a minus
sign, '-', e.g.:
(1) h h ... h
1 2 n
(2) -h h ... h
1 2 n
where h represents an hexadecimal digit.
i
The character string produced will be blank padded on
the right if LENGTH < LEN( STRING ).
LENGTH is the length of the hexadecimal character string
produced by the conversion.
Parameters
None.
Exceptions
Error free.
1) If the output character string is not long enough to
contain the entire hexadecimal string that was produced,
the hexadecimal string will be truncated on the right.
2) If LEN( STRING ) > LENGTH, the output character string will
be blank padded on the right.
Files
None.
Particulars
This routine will convert a signed integer into an equivalent
signed hexadecimal character string. This provides a machine
independent mechanism for storing or porting integer values.
This routine is used by the routine DP2HX which converts a
double precision value into an equivalent character string.
This routine is one of a pair of routines which are used to
perform conversions between integers and equivalent signed
hexadecimal character strings:
INT2HX -- Convert an integer into a signed hexadecimal
character string.
HX2INT -- Convert a signed hexadecimal character string
into an integer.
Examples
All of the values shown are for a two's complement representation
for signed integers.
The following input and output argument values illustrate the
action of INT2HX for various input values of NUMBER.
NUMBER STRING LENGTH
----------- --------------- ------
1 '1' 1
-1 '-1' 2
223 'DF' 2
-32 '-20' 3
0 '0' 1
2147483647 '7FFFFFFF' 8
(Maximum 32 bit integer)
-2147483647 '-7FFFFFFF' 9
(Minimum 32 bit integer + 1)
-2147483648 '-80000000' 9
(Minimum 32 bit integer)
Restrictions
1) The maximum number of characters permitted in the output
string is specified by the local parameter STRLEN.
Literature_References
None.
Author_and_Institution
J. Diaz del Rio (ODC Space)
K.R. Gehringer (JPL)
Version
SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
Added IMPLICIT NONE statement.
Edited the header to comply with NAIF standard.
SPICELIB Version 1.0.0, 22-OCT-1992 (KRG)
|
Fri Dec 31 18:36:27 2021