教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 范文大全 > 公文资料 >

delphi 字符串转二进制怎么转(超经典)

来源:网络收集 时间:2026-08-29
导读: delphi 字符串转二进制怎么转(超经典) unit Convert; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; const //////////////////////////////////////////////////////////////////////////////// //

delphi 字符串转二进制怎么转(超经典)

unit Convert;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

const

////////////////////////////////////////////////////////////////////////////////

// DIGITS Êý×Ö

// Characters that represent each digit. Add more characters to convert numbers

//×Ö·û´ú±íµÄÒ»¸öÊý×Ö £¬Ìí¼Ó¸ü¶àµÄ×Ö·û¶ÔӦת»»µÄÊý×Ö

// with higher bases.

//ͨ¹ý¸ü¸ßµÄλ

Digits : string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

////////////////////////////////////////////////////////////////////////////////

// COMMON BASES ½øÖÆ

// Common values for base representations.

cbBin = 2; // Binary base

cbOct = 8; // Octal base

cbDec = 10; // Decimal base

cbHex = 16; // Hexadecimal base

type

////////////////////////////////////////////////////////////////////////////////

// TCONVERT ת»»

// Converts a number, in string representation, from a base into many others.

//ת»»Ò»¸öÊý×Ö£¬ÓÃ×Ö·û´®ÖÐÏàÓ¦µÄ×Ö·û±íʾ

//

// Start ¿ªÊ¼

// Place a TConvert in the form. Assign Base property the original base of

delphi 字符串转二进制怎么转(超经典)

//

// the number to convert, and assign Text the number to convert. Modify Base

// to change the number's representation; use Common Bases constants or set

// your own base.

//

// Properties

// Base - Defines current base representation.

// Text - Stores the number in string format.

{¿ªÊ¼

ÔÚformÖзÅÈëTConvert¡£Ö¸¶¨ÏàÓ¦µÄÊôÐÔ£¬ºÅÂëҪת»»µÄ½øÖÆ£¬

²¢Ö¸¶¨Îı¾µÄÊý×Öת»»¡£ÐÞ¸ÄÏàÓ¦¸Ä±äÊý×ֵĴú±íÐÔ;ʹÓÃÕûÊýÀ´É趨×Ô¼ºµÄ½øÖÆ¡£

ÊôÐÔ

½øÖÆ- ¶¨Ò嵱ǰ½øÖÆ£¬Èç°Ë½øÖÆ£ºcbOct = 8£»

ÎÄ×Ö -´æ´¢ÔÚ×Ö·û´®ÖеÄÊý×Ö}

TConvert = class(TCustomEdit)

private

{ Private declarations }

FBase : Integer;

FMinDigits : Integer;

procedure SetBase (ABase : Integer);

procedure SetMinDigits (AMinDigits : Integer);

function DigitToValue (Digit : Char) : Integer;

function IsValidBase (Base : Integer) : Boolean;

function PlaceToValue (Place, Base : Integer) : Integer;

function TextToValue (Text : string; Base : Integer) : Integer; function ValueToText (Value, Base : Integer) : string;

function AdjustValue (Text : string; MinDigits : Integer) : string; protected

{ Protected declarations }

constructor Create (AOwner : TComponent); override;

public

{ Public declarations }

published

{ Published declarations }

property Base : Integer read FBase write SetBase;

property MinDigits : Integer read FMinDigits write SetMinDigits; property Text;

property ReadOnly;

property OnChange;

delphi 字符串转二进制怎么转(超经典)

procedure Register;

implementation

procedure TConvert.SetBase (ABase : Integer);

begin

if IsValidBase (ABase) then

begin

Text := AdjustValue (ValueToText (TextToValue (Text, FBase), ABase), MinDigits);

FBase := ABase;

end;

end;

procedure TConvert.SetMinDigits (AMinDigits : Integer);

begin

FMinDigits := AMinDigits;

Text := AdjustValue (ValueToText (TextToValue (Text, Base), Base), MinDigits);

end;

function TConvert.DigitToValue (Digit : Char) : Integer;

var

I : Integer;

begin

Digit := UpCase (Digit);

I := Length (Digits);

while (I > 1) and (Digit <> Digits [I]) do Dec (I);

Result := I - 1;

end;

function TConvert.IsValidBase (Base : Integer) : Boolean;

begin

Result := (Base > 1) and (Base <= Length (Digits));

end;

function TConvert.PlaceToValue (Place, Base : Integer) : Integer;

delphi 字符串转二进制怎么转(超经典)

V, I : Integer;

begin

if IsValidBase (Base) then

begin

V := 1;

for I := 2 to Place do V := V * Base;

Result := V;

end else Result := 0;

end;

function TConvert.TextToValue (Text : string; Base : Integer) Integer;

var

V, I, S : Integer;

begin

if IsValidBase (Base) then

begin

V := 0;

S …… 此处隐藏:2255字,全部文档内容请下载后查看。喜欢就下载吧 ……

delphi 字符串转二进制怎么转(超经典).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/fanwen/2178519.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)