$ ---- HEX.001 ---- $----------------------------------------------------------------------- $; Copyright (C) 1995 $; Associated Universities, Inc. Washington DC, USA. $; $; This program 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 2 of $; the License, or (at your option) any later version. $; $; This program 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 this program; if not, write to the Free $; Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, $; MA 02139, USA. $; $; Correspondence concerning AIPS should be addressed as follows: $; Internet email: aipsmail@nrao.edu. $; Postal address: AIPS Project Office $; National Radio Astronomy Observatory $; 520 Edgemont Road $; Charlottesville, VA 22903-2475 USA $----------------------------------------------------------------------- $procedures to convert decimal to hex $last edited by glen langston on 92 november 12 PROC DECLARE SCALAR HEXIN,HEXWRK,HEXTMP STRING*1 CHARX; STRING*16 NUMCHARS, HEXSTR FIN $HEXDIGIT -- RETURNS THE HEXDIGIT CORRESPONDING TO 0-15 NUMBER PROC HEXDIGIT(X,CHARX) IF (X<=0) THEN CHARX='0'; ELSE IF (X>=15) THEN CHARX='F'; ELSE CHARX=substr(NUMCHARS,X,x) END ; END RET;FIN $HEX - converts the a decimal number < 65536 to hex $ HEXIN - input number (modified if > 65535) $ HEXSTR - output is a 3 or 4 character string PROC HEX(HEXIN) HEXIN=MOD(HEXIN,65536); HEXWRK=ABS(HEXIN) $ 4096 IF (HEXWRK>4095) THEN HEXTMP=FLOOR(MAX(0,HEXWRK/4096)) HEXDIGIT(HEXTMP,CHARX) HEXSTR = CHARX HEXWRK=HEXWRK-HEXTMP*4096 ELSE HEXSTR='' END $ 256 HEXTMP=FLOOR(HEXWRK/256) HEXDIGIT(HEXTMP,CHARX) HEXSTR = HEXSTR!!CHARX HEXWRK=HEXWRK-HEXTMP*256 $ 16 HEXTMP=FLOOR(HEXWRK/16) HEXDIGIT(HEXTMP,CHARX) HEXSTR = HEXSTR!!CHARX HEXWRK=HEXWRK-HEXTMP*16 $ 0 HEXTMP=HEXWRK HEXDIGIT(HEXTMP,CHARX) HEXSTR = HEXSTR!!CHARX IF (HEXIN<0) THEN HEXSTR='-'!!HEXSTR; END TYPE 'HEX('!!CHAR(HEXIN)!!') =', HEXSTR RET; FIN NUMCHARS='123456789ABCDEF0'