Board index » delphi » FAST binary to hex string conversion

FAST binary to hex string conversion

Looking for a *very fast* BASM routine to convert an integer
to a hexadecimal string.   Searched web but came up dry.

Any pointers appreciated.

 

Re:FAST binary to hex string conversion


Quote
b...@unlvx.edu wrote:
> Looking for a *very fast* BASM routine to convert an integer
> to a hexadecimal string.   Searched web but came up dry.

No idea if it's fast enough, but try this:

const
  HexChars : array[0..$F] of char = '0123456789ABCDEF';

function Hex(i: integer): string; assembler;
asm
  les   di, @result
  lea   bx, HexChars
  mov   byte ptr es:[di], 4
  inc   di
  mov   cl, 12
  mov   dx, i
@@1:
  mov   ax, dx
  shr   ax, cl
  and   al, 0Fh
  xlat
  mov   es:[di], al
  inc   di
  sub   cl, 4
  jns   @@1
end;

Other Threads