如何将字符串转换为十六进制而不改变其长度?
我将字符串转换为十六进制,但是当我转换时,十六进制代码有 2*length(string) 我可以这样做“字符串长度=十六进制字符串长度”吗?
我发现这段代码有效吗?
var
fs: TFileStream;
temp: Char;
buffer: string;
pBuffer: PAnsiChar;
text: PAnsiChar;
begin
fs := TFileStream.Create('file way', fmOpenRead or fmShareDenyNone);
fs.Position := 0;
while fs.Position < fs.Size do
begin
fs.Read(temp, 1); //buffer içine her defasında 1 byte gelir.
buffer := buffer + temp;
end;
pBuffer := PAnsiChar(buffer);
BinToHex(pBuffer, text, Length(buffer));
Memo1.Text := text;
end;
I convert string to hex, but when I convert, hex code has 2*length(string) can I do that "string length=hexstring length" is it possible?
I found this code does it work?
var
fs: TFileStream;
temp: Char;
buffer: string;
pBuffer: PAnsiChar;
text: PAnsiChar;
begin
fs := TFileStream.Create('file way', fmOpenRead or fmShareDenyNone);
fs.Position := 0;
while fs.Position < fs.Size do
begin
fs.Read(temp, 1); //buffer içine her defasında 1 byte gelir.
buffer := buffer + temp;
end;
pBuffer := PAnsiChar(buffer);
BinToHex(pBuffer, text, Length(buffer));
Memo1.Text := text;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的唯一方法是以某种方式将字符映射到 4 位值并将其转换为十六进制。这意味着只有十六个值是可能的,所以,不,如果有超过十六种可能性,则不能以一般方式执行此操作。
八位值(或五到八位的任何长度)每个值需要两个十六进制数字。
The only way to do this is to map the characters to 4-bit values somehow and convert that to hex. That will mean only sixteen values are possible so, no, you can't do this in a general way if there are more than sixteen possibilities.
Eight-bit values (or any length from five to eight bits) requires two hex digits per value.