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?
Posted on 2001-06-06 21:23:00 by HeroInc
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.
Posted on 2001-06-07 02:22:00 by Larry Hammick
First off, wsprintf has no print-as-binary option.... In the examples below the lpFormat variable is in the invoke for ease of reading!
invoke wsprintf, addr buffer, "%xh", myNumber
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, "%d", myNumber
This will "print" a signed decimal integer to the buffer.
invoke wsprintf, addr buffer, "%u", 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.

        mov eax, myNumber
        mov ecx, 32

            xor edx, edx
            shr eax, 1
            adc dl, 48
            mov buffer, dl
            dec ecx
        .UNTIL ecx == 0
Hope that helps. Mirno
Posted on 2001-06-07 05:42:00 by Mirno