delphi 字符串转二进制怎么转(超经典).doc_第1页
delphi 字符串转二进制怎么转(超经典).doc_第2页
delphi 字符串转二进制怎么转(超经典).doc_第3页
delphi 字符串转二进制怎么转(超经典).doc_第4页
delphi 字符串转二进制怎么转(超经典).doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

delphi 字符串转二进制怎么转(超经典).txt第一次笑是因为遇见你,第一次哭是因为你不在,第一次笑着流泪是因为不能拥有你。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 basecbDec = 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/ the number to convert, and assign Text the number to convert. Modify Base/ to change the numbers 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; end; 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 0 do begin T := Digits (Value mod Base) + 1 + T; Value := Value div Base; end; Result := T; end; end else Result := ; end; function TConvert.AdjustValue (Text : string; MinDigits : Integer) : string; var S : Integer; begin S := Length (Text); if MinDigits S then begin Dec (MinDigits, S); for S := MinDigits downto 1 do Text := Digits 1 + Text; end; Result := Text; end; constructor TConvert.Create (AOwner

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论