Hi,
I have a char, it's "61", now i want to convert into the hex of it ,"3D" in this case for "61".
So how can I convert a char(it's alaways a number from 0-61) into it's hex value?
:alright:
I have a char, it's "61", now i want to convert into the hex of it ,"3D" in this case for "61".
So how can I convert a char(it's alaways a number from 0-61) into it's hex value?
:alright:
Hi flapper
You can use wsprintf, with the following format specification:
lx, lX Long unsigned hexadecimal integer in lowercase or uppercase.
That should do the trick :)
regards,
The SharK
You can use wsprintf, with the following format specification:
lx, lX Long unsigned hexadecimal integer in lowercase or uppercase.
That should do the trick :)
regards,
The SharK
thanks, is there another way? Without the use of an API call?
thanks to you, how can I use this code?
Edit: why you deleted your post donkey?
Edit: why you deleted your post donkey?
You can use a lookup table - either a 0-255 entry table of 2xChar, or a 0-15 (nibble) table (requires slightly more code).
http://www.asmcommunity.net/board/index.php?topic=18766
http://www.asmcommunity.net/board/index.php?topic=18766
offtopic: Is a char with "61" the same as an integer with "61" ?
A char is 8 bit.
61 is TWO char's made of 0x36 and 0x31.
61 is TWO char's made of 0x36 and 0x31.
Sorry flapper there was a mistake in it. this should do it for ya. Good from 0-99
hextab DB "0123456789ABCDEF"
xor eax,eax
mov al,[szDec]
sub al,30h
mov dl,[szDec+1]
or dl,dl
jz >
mov ecx,10
mul cl
sub dl,30h
add al,dl
:
and eax,0FFh
xor edx,edx
mov edi,offset hextab
movzx ecx,al
shr ecx,4
mov dl,[edi+ecx]
mov [szHex],dl
movzx ecx,al
and ecx,0fh
mov dl,[edi+ecx]
mov [szHex+1],dl
okay, thanks.
@f0dder : Im a complete noob, can you give me an example?
@donkey : Where do I tell that code what my CHAR is?
@f0dder : Im a complete noob, can you give me an example?
@donkey : Where do I tell that code what my CHAR is?
The 2 byte ascii decimal string is in szDec, it must be null terminated. The output is into szHex.
For example
szDec DB "61",0
szHex DB 4 DUP (?)
Will output :
szHex = "3D"
For example
szDec DB "61",0
szHex DB 4 DUP (?)
Will output :
szHex = "3D"
Thanks, it worked :alright:
One problem:
I call a function that will return this number (61 in this case).
when I do mov szDec, eax i get an error
I call a function that will return this number (61 in this case).
when I do mov szDec, eax i get an error
You have to move it to an undefined string.
You're trying to move a value to a defined string.
Use szHex instead :alright:
You're trying to move a value to a defined string.
Use szHex instead :alright:
If the number you wish to convert is already in DWORD format just call the routine starting at the following line. Leave the number in EAX and there is no need for szDec. And next time as a little suggestion do not enclose the number in quotes, I thought you meant it was in string format.
mov edi,offset hextab
movzx ecx,al
shr ecx,4
mov dl,[edi+ecx]
mov [szHex],dl
movzx ecx,al
and ecx,0fh
mov dl,[edi+ecx]
mov [szHex+1],dl
lol yes it is in string format, I call a function it returns me for example "61", it's a char, same like "ABC-XYZ"
MY problem is this: invalid instruction operands
.data?
szDec DB ?
szHex DB 4 dup (?)
.code
call dword ptr <- Function that will return the CHAR
mov szDec, eax <-- There's the error
after this I want to convert the CHAR MyFunction returned to HEX and write it into a memory position:
mov esi, 01020304
mov eax, szHex <-- Same error again : invalid instruction operands
mov dword ptr , eax
MY problem is this: invalid instruction operands
.data?
szDec DB ?
szHex DB 4 dup (?)
.code
call dword ptr <- Function that will return the CHAR
mov szDec, eax <-- There's the error
after this I want to convert the CHAR MyFunction returned to HEX and write it into a memory position:
mov esi, 01020304
mov eax, szHex <-- Same error again : invalid instruction operands
mov dword ptr , eax
First off function calls are always DWORDs so why waste typing telling the compiler what it already knows...
call dword ptr is the same as call
However, because you are using MASM and it has stricter types than other assemblers you must type cast the buffer. This is where you actually need DWORD PTR...
mov DWORD PTR szDec, eax
same here...
mov eax, DWORD PTR szHex
call dword ptr is the same as call
However, because you are using MASM and it has stricter types than other assemblers you must type cast the buffer. This is where you actually need DWORD PTR...
mov DWORD PTR szDec, eax
same here...
mov eax, DWORD PTR szHex
:) Now I have this error:
mov esi, 01020304
mov eax, dword ptr
mov byte ptr , eax <-- invalid instruction operands
mov esi, 01020304
mov eax, dword ptr
mov byte ptr , eax <-- invalid instruction operands
EAX is a DWORD, you cannot mov it as a BYTE. Use...
mov , al
Since AL is a byte sized register there is no need to specify BYTE PTR with an untyped memory location (one that is pointed to by a register).
mov , al
Since AL is a byte sized register there is no need to specify BYTE PTR with an untyped memory location (one that is pointed to by a register).
Works.
Just if I look in the program where I wrote the Hex in, it's always another value, sometimes 51, sometimes 55 decimal :(
Just if I look in the program where I wrote the Hex in, it's always another value, sometimes 51, sometimes 55 decimal :(
It doesn't seem to work properly, when the first function return 0 the hex value is something for 50 in decimal, never the same, weird!