I have a string that will contain either all decimal chars, hexadecimal chars, or binary charcter and ill need to change that string from one (dec, hex or bin) to the other (dec, hex or binary). In the program, Ill know which type (dec, hex or bin) the string will contain. How do i go about doing this using wsprintf?
I don't know in terms of wsprintf, which I seldom use. But you could write 6 little routines: one to convert each of the three types to a 32-bit or 64-bit integer, and one to convert an integer back to each of the three formats. Then you could go from any format to any other, and the asm source would surely be useful on future jobs. I can post some of my own stuff if you like.
First off, wsprintf has no print-as-binary option.... In the examples below the lpFormat variable is in the invoke for ease of reading!
This will write the ascii characters of "myNumber" in hex format to "buffer". "%x" Means hex, the h after it is our notation for a hex value (some people use "0x" infront of the hex value, this is done like so "0x%x"). You can also use %X, using a capital 'x' denotes the alphabetic characters being in upper case.
invoke wsprintf, addr buffer, "%xh", myNumber
This will "print" a signed decimal integer to the buffer.
invoke wsprintf, addr buffer, "%d", myNumber
will "print" an unsigned decimal number to the buffer. wsprintf WILL NOT convert from one kind to another! In order to print out the binary I have this code (although elsewhere on the board there is a faster algo by the Svin I think) which is very simple.
invoke wsprintf, addr buffer, "%u", myNumber
Hope that helps. Mirno
mov eax, myNumber mov ecx, 32 .REPEAT xor edx, edx shr eax, 1 adc dl, 48 mov buffer, dl dec ecx .UNTIL ecx == 0