I dont mind bug: BinToHex implementation/description do not match !
From: Skybuck Flying (nospam_at_hotmail.com)
Date: 11/25/04
- Next message: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Previous message: Nicolai Hansen: "Re: format string bug ?!?"
- Next in thread: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Maybe reply: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Reply: Jamie: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Nov 2004 09:09:14 +0100
Hello,
The BinToHex procedure occurding to Delphi's help would return a 'null'
terminated text string.
This is not the case.
The implementation simply converts all binary values to hex values but
forgets to add a null terminated character.
Actually I don't really mind this bug.
Since it's a quite stupid prototype design anyway... why would anyway want
to terminate it with a #0 in the first place.
That would limit it's use somewhat to pchars only.
A better prototype would simply be this:
procedure BinToHex( const BinaryBuffer; var HexBuffer; BufSize: Integer);
Also it says "assembler" at the end... but the whole procedure is not in
assembler it's just in pascal hehe.
procedure BinToHex(Buffer, Text: PChar; BufSize: Integer); assembler;
const
Convert: array[0..15] of Char = '0123456789ABCDEF';
var
I: Integer;
begin
for I := 0 to BufSize - 1 do
begin
Text[0] := Convert[Byte(Buffer[I]) shr 4];
Text[1] := Convert[Byte(Buffer[I]) and $F];
Inc(Text, 2);
end;
end;
I guess in the past there was also an ASM version:
It's commented so maybe it mal functioned :D I dont know =D
{asm
PUSH ESI
PUSH EDI
MOV ESI,EAX
MOV EDI,EDX
MOV EDX,0
JMP @@1
@@0: DB '0123456789ABCDEF'
@@1: LODSB
MOV DL,AL
AND DL,0FH
MOV AH,@@0.Byte[EDX]
MOV DL,AL
SHR DL,4
MOV AL,@@0.Byte[EDX]
STOSW
DEC ECX
JNE @@1
POP EDI
POP ESI
end;}
"
Call BinToHex to convert the binary value in a buffer into a string that is
its hexadecimal representation.
Buffer is a buffer of bytes that contains the binary value.
Text returns a null-terminated string that represents the value of Buffer as
a hexadecimal number.
BufSize is the size of Buffer. Text needs to point to a sequence of
characters that has at least 2*BufSize bytes because each hexadecimal
character represents two bytes.
"
P.S.:
!!!!! Fortunately I have the Delphi VCL source code !!!!! Otherwise I would
be pretty screwed by now !!!!! =D
Bye,
Skybuck.
- Next message: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Previous message: Nicolai Hansen: "Re: format string bug ?!?"
- Next in thread: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Maybe reply: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Reply: Jamie: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|