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

  1. * Program..: DEC2HEX.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 decimal integers (1-65535) to hex.
  7. *
  8. SET TALK OFF
  9. SET EXACT ON
  10. STORE "0123456789ABCDEF" TO hexstr
  11. DO WHILE T
  12.    STORE "     " TO decstr
  13.    ACCEPT "Decimal integer -->" TO decstr
  14.    STORE VAL(decstr) TO dec
  15.    *
  16.    DO CASE
  17.       CASE decstr = "     "
  18.          RELEASE dec,decstr,hexstr,hexresult
  19.          SET EXACT OFF
  20.          SET TALK ON
  21.          RETURN
  22.       CASE dec > 0 .AND. dec < 16
  23.          STORE $(hexstr,INT(dec)+1,1) TO hexresult
  24.       CASE dec > 15 .AND. dec < 256
  25.          STORE $(hexstr,INT(dec/16)+1,1)+;
  26.                $(hexstr,(dec/16.0000-INT(dec/16))*16+1,1) TO hexresult
  27.       CASE dec > 255 .AND. dec < 4096
  28.          STORE $(hexstr,INT(dec/256)+1,1)+;
  29.                $(hexstr,(dec/256.0000-INT(dec/256))*16+1,1)+;
  30.                $(hexstr,(dec/ 16.0000-INT(dec/ 16))*16+1,1) TO hexresult
  31.       CASE dec > 4095 .AND. dec < 65536
  32.          STORE $(hexstr,INT(dec/4096)+1,1)+;
  33.                $(hexstr,(dec/4096.0000-INT(dec/4096))*16+1,1)+;
  34.                $(hexstr,(dec/ 256.0000-INT(dec/ 256))*16+1,1)+;
  35.                $(hexstr,(dec/  16.0000-INT(dec/  16))*16+1,1) TO hexresult
  36.       OTHERWISE
  37.          STORE " " TO hexresult
  38.    ENDCASE
  39.    *
  40.    IF hexresult > " "
  41.       ? "Hexadecimal  =  -->:" + hexresult
  42.       ?
  43.    ELSE
  44.       ? "Decimal number must be 1-65535."
  45.       ?
  46.    ENDIF
  47.    *
  48. ENDDO
  49. * EOF: Dec2hex.prg