News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to recode the Bin2Dec

Started by Eric4ever, April 20, 2006, 02:21:03 AM

Previous topic - Next topic

Eric4ever

This is a piece of code I found in the web, and it works well.
But the DWORD var X define as "X dword ****b", I just want to make it a real X: input the binary(0 & 1) into a Edittext, and use  GetDlgItemInt or GetDlgItemText to get it, I tried but failed.

How can I do that? THX. The snipplet is below:

.386
.model flat,stdcall
option casemap:none

includelib msvcrt.lib
printf PROTO C :dword,:vararg

.data
X dword 00011000111011110001001101100101b

dStr byte 10 dup(?),0     
szFmt  byte 'dec format = %sd',0ah     

.code
start:

mov ecx,10         
mov eax,X         
xor edx,edx         
mov ebx,10

f70:
    div ebx         
add dl,'0'           
mov dStr[ecx-1],dl 
xor edx,edx         
    loop f70             

invoke printf,offset szFmt,\
  offset dStr

ret
end start

MichaelW

In the snippet you posted the code from "start" to "loop f70" converts a dword value to a decimal string. It seems that you are asking how to convert a binary string input by the user to a dword value. I'm not aware of any procedure that does this in the MASM32 library, but the MSVCRT strtol or strtoul functions can do it, or you could code your own procedure. The C source for strtol was included with the February 2003 version of the PSDK, and probably with later versions.
eschew obfuscation

hutch--

here are two procs in the masm32 library that handle the conversion in both directions. "byt2bin_ex" handles converting BYTE data to binary string data while "bin2byte_ex" handles the conversion in the other direction. Both algos are designed for streaming data at high speed and are larger than average because of their design.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php