home *** CD-ROM | disk | FTP | other *** search
/ Software Du Jour / SoftwareDuJour.iso / BUSINESS / DBASE / DBAPG.ARC / HEX2DEC.PRG < prev    next >
Encoding:
Text File  |  1984-08-12  |  1.6 KB  |  53 lines

  1. * Program..: HEX2DEC.PRG
  2. * Author...: Tom Rettig
  3. * Date.....: September 24, 1983
  4. * Notice...: Copyright 1983, Ashton-Tate, All Rights Reserved
  5. * Version..: dBASE II, versions 2.3x, 2.4x
  6. * Notes....: For converting hexadecimal numbers (1-FFFF) to decimal.
  7. *
  8. SET TALK OFF
  9. SET EXACT ON
  10. STORE "123456789ABCDEF" TO hexstr
  11. DO WHILE T
  12.    ACCEPT "Hexadecimal -->" TO hex
  13.    STORE !(hex) TO hex
  14.    *
  15.    DO CASE
  16.       CASE hex = " "
  17.          RELEASE hex,hexstr,decresult,decstr
  18.          SET EXACT OFF
  19.          SET TALK ON
  20.          RETURN
  21.       CASE LEN(hex) = 1 .AND. VAL(hex) >= 0
  22.          STORE @(hex,hexstr) TO decresult
  23.       CASE LEN(hex) = 2 .AND. VAL(hex) >= 0
  24.          STORE (@( $(hex,1,1) ,hexstr) * 16) +;
  25.                 @( $(hex,2,1) ,hexstr) TO decresult
  26.       CASE LEN(hex) = 3 .AND. VAL(hex) >= 0
  27.          STORE (@( $(hex,1,1) ,hexstr) * 256) +;
  28.                (@( $(hex,2,1) ,hexstr) *  16) +;
  29.                 @( $(hex,3,1) ,hexstr) TO decresult
  30.       CASE LEN(hex) = 4 .AND. VAL(hex) >= 0
  31.          STORE (@( $(hex,1,1) ,hexstr) * 4096) +;
  32.                (@( $(hex,2,1) ,hexstr) *  256) +;
  33.                (@( $(hex,3,1) ,hexstr) *   16) +;
  34.                 @( $(hex,4,1) ,hexstr) TO decresult
  35.       OTHERWISE
  36.          STORE 0 TO decresult
  37.    ENDCASE
  38.    *
  39.    IF decresult > 0
  40.       STORE STR(decresult,5) TO decstr
  41.       DO WHILE $(decstr,1,1) = " "
  42.          STORE $(decstr,2) TO decstr
  43.       ENDDO
  44.       ? "Decimal  =  -->:" + decstr
  45.       ?
  46.    ELSE
  47.       ? "Hex number must be between 1-FFFF."
  48.       ?
  49.    ENDIF
  50.    *
  51. ENDDO
  52. * EOF: Hex2dec.prg
  53.