flat assembler
Message board for the users of flat assembler.

Index > Windows > [HELP] - Converting string of integers to hexadecimal

Author
Thread Post new topic Reply to topic
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Hi folks,

Need help to convert a string of integers to it's hexadecimal representation. Could someone help me please?

Example:
string "4340934073110" to this string "00003F2B3D55B16"

Cheers,
ctl3d32
Post 08 Feb 2011, 21:07
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Well, there are two tasks - converting string to number and from number to string, but with different radix.
FreshLib have a library StrLib where exists both NumToStr and StrToNum procedures.
You can download FreshLib with Fresh
The file is: Fresh/FreshLib/data/StrLib.asm
At least you can get some ideas from the source.
Post 08 Feb 2011, 21:48
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
data should be held in normal form.

Then get lowest 16^1/2 bits, map to 16 possible codepoints, write out codepoint, shift data pointer up, repeat untill pointer reach beyond data.


The other way around is to get a codepoint, convert to real data, and add to buffer in the current pointer position*4. Increment ponter. Repeat untill pointer reach beyond string data.

Converting decimal string is same.
You take a character, convert it into a data, add into buffer. But here you have to multiply it before, because 10 cant be represented as a single 2^n and because of this you cant multiply-by-shift.
Post 08 Feb 2011, 23:40
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Thanks for the quick reply! I will give it a try.
Post 09 Feb 2011, 00:28
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Since this is the Windows section, if your only looking at 64bit hex numbers then a lazy way (32-bit code) might be
Code:
;----------------------------------------
section '.text' code readable executable

        cinvoke wsprintf,Buff,wsformat,dword[num],dword[num+4]
        invoke  MessageBox,0,Buff,0,0
        invoke  ExitProcess,0

;----------------------------------------
section '.data' data readable writeable

  wsformat      db '%016I64X',0
align 4
  num           dq 4340934073110
  Buff          rb 20     


whoops, thanks Rev.


Last edited by Alphonso on 09 Feb 2011, 10:24; edited 3 times in total
Post 09 Feb 2011, 10:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
Alphonso: use cinvoke for wsprintf.
Post 09 Feb 2011, 10:09
View user's profile Send private message Visit poster's website Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Thanks bro!
Post 09 Feb 2011, 22:19
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.