TURBO PASCAL |
Новости
|
42: How do I convert a decimal word into a hexadecimal string, etc?A: Here is one possibility function HEXFN (decimal : word) : string; const hexDigit : array [0..15] of char = '0123456789ABCDEF'; begin hexfn := hexDigit[(decimal shr 12)] + hexDigit[(decimal shr 8) and $0F] + hexDigit[(decimal shr 4) and $0F] + hexDigit[(decimal and $0F)]; end; (* hexfn *) Here is another conversion example (from longint to binary string) function LBINFN (decimal : longint) : string; const BinDigit : array [0..1] of char = '01'; var i : byte; binar : string; begin FillChar (binar, SizeOf(binar), ' '); binar[0] := chr(32); for i := 0 to 31 do binar[32-i] := BinDigit[(decimal shr i) and 1]; lbinfn := binar; end; (* lbinfn *) For a full set of conversions, both from and to decimal, apply TSUTNTB.TPU from ftp://garbo.uwasa.fi/pc/ts/tspa3470.zip. |
(с)Все права защищены По всем интересующим вопросам прошу писать на электронный адрес |