delphi 字符串转二进制怎么转(超经典)
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;
相关推荐:
- [公文资料]市场营销专员岗位职责
- [公文资料]综合部经理岗位职责
- [公文资料]会计助理岗位职责
- [公文资料]林业站站长职责
- [公文资料]菜品研发部岗位职责
- [公文资料]街道综治办工作职责
- [公文资料]酒店前台的工作职责
- [公文资料]销售部经理岗位职责
- [公文资料]工程部副经理岗位职责
- [公文资料]手术室护士工作职责
- [公文资料]银行客户经理职责
- [公文资料]汽车4s店市场专员职责
- [公文资料]服装店长工作职责
- [公文资料]采购总监岗位职责
- [公文资料]大学行政秘书工作职责
- [公文资料]学校财务人员岗位职责
- [公文资料]财务统计员岗位职责
- [公文资料]物业工程主管工作职责
- [公文资料]公司后勤工作职责
- [公文资料]采矿工程师岗位职责
- 门面出租合同样板(门面出租的合同)
- 自用房屋租赁合同 自住房租房合同(汇总
- 最新酒店劳动合同管理制度(11篇)(酒店
- 2025年无产权车库买卖合同实用(14篇)(
- 建筑工程农民工劳动合同十五篇(通用)(
- 最新深圳标准劳动合同 深圳劳动合同如
- 解除劳动合同通知书(实用6篇)(解除劳动
- 2025年二手房屋买卖合同范围精选(二十
- 最新融资贷款居间合同大全(22篇)(融资
- 2025年个人二手房屋买卖合同协议书四篇
- 2025年果树苗木买卖合约书 签订果树苗
- 广东省劳动合同书填写(21篇)(广东省劳
- 最新餐饮行业没有劳动合同 劳动法餐饮
- 农村土地买卖合同(汇总21篇)(农村土地
- 最新房屋转租合同模版21篇(通用)(标准
- 2025年进口合同号查询五篇(大全)(进口
- 农村建房包工包料合同(通用8篇)(农村建
- 2025年安装监控合同协议书(15篇)(2025
- 2025年企业租赁经营合同(模板9篇)(2025
- 最新郊区土地租赁合同(优质23篇)(最新




