




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 餐饮合作协议的基本示本
- 产业链技术标准统一-洞察与解读
- 2025年四川省事业单位教师招聘考试生物学科专业知识真题模拟试卷
- 2025年陕西西安事业单位招聘考试综合类专业能力测试试卷(艺术设计类)真题模拟解析
- 2025年天津市和平区面向靖远籍招聘事业单位工作人员模拟试卷参考答案详解
- 2025年综合类事业单位招聘考试公共基础知识真题模拟试卷(河北)
- 跨境支付合规难题-洞察与解读
- 贺州期末考试卷子及答案
- 2025年中国无线智能可视门铃行业市场分析及投资价值评估前景预测报告
- 北师大版八年级上学期数学第四章一次函数第2节认识一次函数练习题(含答案)
- 高三试卷:山东省名校考试联盟2024-2025学年高三上学期期中考试化学+答案
- 广东上进联考2025-2026学年领航高中联盟2026届高三10月一轮复习阶段检测化学(含答案)
- 2024年全国统计师之初级统计基础理论及相关知识考试快速提分卷(附答案)
- 土地法律知识培训内容课件
- 2025年湖北省荆门市辅警考试题库(附答案)
- 气象科研课题申报书
- 人工智能+开放共享城市安全监控数据共享分析报告
- 2023年中级统计师《统计工作实务》试题真题及答案
- 新疆质量安全总监培训课件
- 心理健康指导手册方案
- 电厂安全学习培训课件
评论
0/150
提交评论