Re: I dont mind bug: BinToHex implementation/description do not match !
From: Jamie (jamie_5_not_valid_after_5_Please_at_charter.net)
Date: 11/25/04
- Next message: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Previous message: J French: "Re: Dumb question"
- In reply to: Skybuck Flying: "I dont mind bug: BinToHex implementation/description do not match !"
- Next in thread: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Reply: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Nov 2004 11:53:28 -0800
why don't you try the original one, IntTohex.
the returns the same results and gives you the
null at the end.
also i really don't see the relevance to it since
it's a function and there for being assigned to a
string would most likely end up putting a null at the
end any ways..
i guess if you were trying to do some direct index
referencing from the return value instead of simply
assigning it to another string you may see this problem.
Skybuck Flying wrote:
> 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: J French: "Re: Dumb question"
- In reply to: Skybuck Flying: "I dont mind bug: BinToHex implementation/description do not match !"
- Next in thread: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Reply: Skybuck Flying: "Re: I dont mind bug: BinToHex implementation/description do not match !"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|