flat assembler
Message board for the users of flat assembler.

Index > Windows > hexadecimal integer to a string

Author
Thread Post new topic Reply to topic
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
good evening

i have big buffer with a hexadecimal integer, and i wan't to convert this to a string, how can i do that and which method is better/faster?

thanks

_________________
[not enough memory]
Post 02 Jul 2005, 17:10
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
Something like (not tested):
Code:
hex_table db '0123456789ABCDEF'
...
mov esi,source
mov edi,destination
mov ecx,source_length
cld
@@:
lodsb
mov dl,al
and eax,0x0F
mov al,[eax+hex_table]
stosb
mov al,dl
shr al,4
and eax,0x0F
mov al,[eax+hex_table]
stosb
loop @b    
Post 02 Jul 2005, 17:47
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Larger table can be used to get better speed:
Code:
hex_table:
repeat 256
 l = (%-1) and 0Fh
 h = (%-1) shr 4
 if h < 10
  db '0'+h
 else
  db 'A'+h-10
 end if
 if l < 10
  db '0'+l
 else
  db 'A'+l-10
 end if
end repeat

...

mov esi,source
mov edi,destination
mov ecx,source_length
cld
xor edx,edx
@@:
mov dl,[esi]
inc esi
mov ax,[hex_table+edx*2]
stosw
loop @b    
Post 02 Jul 2005, 19:28
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
big thanks for help
Post 04 Jul 2005, 05:01
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.