Unlimited credit conversion

xiaoxiao2021-03-06  93

Unlimited conversion (* //

Title: Unlimited Broken Conversion

Description: Use each other between mathematics

Design: zswang

Date: 2002-01-24

Support: wjhu111@21cn.com

// *)

/// begin Source

Const

Cscalechar = '0123456789abcdefghijklmnopqrstuvwxyz';

Function Intpower (Base, Exponent: Integer): Integer; {Return Basent Extra}

VAR

I: integer;

Begin

RESULT: = 1;

For i: = 1 to EXPONENT DO

Result: = Result * Base;

End; {intpower}

Function INTTODIGIT (Mnumber: INTEGER; MSCALE: BYTE

MLENGTH: Integer = 0): String;

{Return to an integer representation; MSCALE specifies how much; MLENGTH specifies the length, and the length is not enough to make up 0}

VAR

I, J: Integer;

Begin

Result: = '';

I: = mnumber;

While (I> = mscale) and (mscale> 1) do begin

J: = I mod mscale;

I: = I Div Mscale;

Result: = cscalechar [J 1] Result;

END;

Result: = cscalechar [i 1] result;

For i: = 1 to mlength - length (result) do result: = '0' result;

End; {INTTODIGIT}

Function Digittoint (mdigit: string; mscale: byte): integer;

{Return to the credit representation to the integer; MSCALE specifies how much}

VAR

I: byte;

L: integer;

Begin

Result: = 0;

Mdigit: = Uppercase (mdigit);

L: = Length (mdigit);

For i: = 1 to L DO

Result: = Result (POS (MDigit [L - i 1], Cscalechar) - 1) *

INTPOWER (Mscale, I - 1);

End; {DigitToint}

/// end source

/// Begin Demo

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

Edit1.text: = INTTODIGIT (STRTOINTDEF (EDIT2.TEXT, 0), 16);

END;

Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT);

Begin

Edit2.text: = INTTOSTR (DigitToint (Edit1.Text, 16);

END;

/// end demo

转载请注明原文地址:https://www.9cbs.com/read-105520.html

New Post(0)