home *** CD-ROM | disk | FTP | other *** search
- * Program..: HEX2DEC.PRG
- * Author...: Tom Rettig
- * Date.....: September 24, 1983
- * Notice...: Copyright 1983, Ashton-Tate, All Rights Reserved
- * Version..: dBASE II, versions 2.3x, 2.4x
- * Notes....: For converting hexadecimal numbers (1-FFFF) to decimal.
- *
- SET TALK OFF
- SET EXACT ON
- STORE "123456789ABCDEF" TO hexstr
- DO WHILE T
- ACCEPT "Hexadecimal -->" TO hex
- STORE !(hex) TO hex
- *
- DO CASE
- CASE hex = " "
- RELEASE hex,hexstr,decresult,decstr
- SET EXACT OFF
- SET TALK ON
- RETURN
- CASE LEN(hex) = 1 .AND. VAL(hex) >= 0
- STORE @(hex,hexstr) TO decresult
- CASE LEN(hex) = 2 .AND. VAL(hex) >= 0
- STORE (@( $(hex,1,1) ,hexstr) * 16) +;
- @( $(hex,2,1) ,hexstr) TO decresult
- CASE LEN(hex) = 3 .AND. VAL(hex) >= 0
- STORE (@( $(hex,1,1) ,hexstr) * 256) +;
- (@( $(hex,2,1) ,hexstr) * 16) +;
- @( $(hex,3,1) ,hexstr) TO decresult
- CASE LEN(hex) = 4 .AND. VAL(hex) >= 0
- STORE (@( $(hex,1,1) ,hexstr) * 4096) +;
- (@( $(hex,2,1) ,hexstr) * 256) +;
- (@( $(hex,3,1) ,hexstr) * 16) +;
- @( $(hex,4,1) ,hexstr) TO decresult
- OTHERWISE
- STORE 0 TO decresult
- ENDCASE
- *
- IF decresult > 0
- STORE STR(decresult,5) TO decstr
- DO WHILE $(decstr,1,1) = " "
- STORE $(decstr,2) TO decstr
- ENDDO
- ? "Decimal = -->:" + decstr
- ?
- ELSE
- ? "Hex number must be between 1-FFFF."
- ?
- ENDIF
- *
- ENDDO
- * EOF: Hex2dec.prg