News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

binary to ascii

Started by hfheatherfox07, December 21, 2012, 03:44:57 PM

Previous topic - Next topic

hfheatherfox07

Quote from: MichaelW on January 02, 2013, 06:48:58 PM
Is this a string of binary digits?

01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

Or a binary representation of 11 bytes?

I am trying to make an app that converts like this http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp

So what ever that is

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

This is what I had in mind , except it is not working

.486p
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

Bin2ASCII proto :DWORD,:DWORD

.data
szBinaryLookup db 01000001b,01000010b,01000011b
format db "%x",0
szBinaryString  db "010000010100001001000011" ; ABC
mybuffer db 4096 dup(?) ; total converted string
buffer   db 4096 dup(?) ; buffer
szCapt   db "Binary To ASCII text", 0
.code

start:

invoke Bin2ASCII,addr szBinaryString,addr buffer
invoke wsprintf, ADDR buffer, ADDR format, edi
invoke lstrcat, ADDR mybuffer, ADDR buffer
invoke MessageBox,NULL,addr buffer,addr szCapt,MB_OK
Invoke ExitProcess,0
Bin2ASCII proc  src:DWORD, dst :DWORD



pushad                 ;save all cpu registers

mov esi,src            ;point to source
mov edi,dst            ;point to destination

mov ecx, sizeof szBinaryString - 1
Convert:
lodsb
mov ah, al
and al, 0FFh
movzx edx, al
mov al, [szBinaryLookup + edx]
stosb

shr ah, 4
movzx edx, ah
mov al, [szBinaryLookup + edx]
stosb

dec ecx
jnz Convert

ret
popad
Bin2ASCII endp

end start
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

ScanBytes FRAME pszString,pBuffer
uses edi,esi

// scan 8 bits at a time
xor ecx,ecx
mov edi,[pszString]
mov esi,[pBuffer]

.NEWBYTE
mov B[esi],0
mov ecx,7
.SETBYTE
mov al,[edi]
cmp al,"1"
jne >.SKIP
bts [esi],cx
.SKIP
inc edi
dec ecx
jns <.SETBYTE
inc esi
mov al,[edi]
test al,al
jnz <.NEWBYTE

ret
endf


Be sure to strip the spaces before you run it through the grinder.

My output for your string was

Line 50: Output = Hello World

EDIT:

This is my attempt at translating to MASM, should work but might need some correcting

ScanBytes PROC uses edi esi pszString:DWORD,pBuffer:DWORD
xor ecx,ecx
mov edi,[pszString]
mov esi,[pBuffer]

NEWBYTE:
mov BYTE PTR [esi],0
mov ecx,7
SETBYTE:
mov al,[edi]
cmp al,49
jne SKIP
bts [esi],cx
SKIP:
inc edi
dec ecx
jns SETBYTE
inc esi
mov al,[edi]
test al,al
jnz NEWBYTE
ret
ENDP
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

@Donkey I am not sure how you intended that ?
.486p
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

ScanBytes proto :DWORD,:DWORD

.data
szCapt   db "Binary To ASCII text", 0
szBinaryLookup db 01000001b,01000010b,01000011b
format db "%x",0
szBinaryString  db "010000010100001001000011" ; ABC  010000010100001001000011 or  01000001 01000010 01000011
.data?
mybuffer db 4096 dup(?) ; total converted string
buffer   db 4096 dup(?) ; buffer
B dd ?
.code

start:

invoke ScanBytes,addr szBinaryString,addr buffer
invoke wsprintf, ADDR buffer, ADDR format, esi
invoke lstrcat, ADDR mybuffer, ADDR buffer
invoke MessageBox,NULL,addr mybuffer,addr szCapt,MB_OK
Invoke ExitProcess,0

ScanBytes PROC uses edi esi pszString:DWORD,pBuffer:DWORD
xor ecx,ecx
mov edi,[pszString]
mov esi,[pBuffer]

NEWBYTE:
mov BYTE PTR [esi],0
mov ecx,7
SETBYTE:
mov al,[edi]
cmp al,49
jne SKIP
bts [esi],cx
SKIP:
inc edi
dec ecx
jns SETBYTE
inc esi
mov al,[edi]
test al,al
jnz NEWBYTE
ret

ScanBytes endp

end start
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

Hi,

I saw the link in your post above and thought you were trying to convert binary represented as a string of 0 and 1 characters into useable ascii text. For example the message in your link decodes as:

Be sure to drink your Ovaltine.

In order to execute the routine, use the following:

invoke StripSpaces,offset String1,offset StringOut
invoke ScanBytes,offset StringOut,offset Output


Works like a charm here.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

Yap I made an error trying to format it  ::)

It works like a charm!!!!  :greenclp:
I translate Perfect!!!
Thanks Donkey  :biggrin:

I took the Binary Message that site had and it converted it Perfect !!!

.486p
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

ScanBytes proto :DWORD,:DWORD

.data
szCapt   db "Binary To ASCII text", 0

StringOut  db "01000010011001010010000001110011011101010111001001100101001000000111010001101111001000000110010001110010011010010110111001101011001000000111100101101111011101010111001000100000010011110111011001100001011011000111010001101001011011100110010100101110"
.data?

Output   db 4096 dup(?) ; total converted string buffer

.code

start:


invoke ScanBytes,offset StringOut,offset Output
invoke MessageBox,NULL,addr Output,addr szCapt,MB_OK
Invoke ExitProcess,0

ScanBytes PROC uses edi esi pszString:DWORD,pBuffer:DWORD
xor ecx,ecx
mov edi,[pszString]
mov esi,[pBuffer]

NEWBYTE:
mov BYTE PTR [esi],0
mov ecx,7
SETBYTE:
mov al,[edi]
cmp al,49
jne SKIP
bts [esi],cx
SKIP:
inc edi
dec ecx
jns SETBYTE
inc esi
mov al,[edi]
test al,al
jnz NEWBYTE
ret

ScanBytes endp

end start
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

Quote from: hfheatherfox07 on January 02, 2013, 07:58:43 PM
Thanks Donkey  :biggrin:

Any time, it was an interesting problem. Hockey is about to start, damn those Russians for not living in a decent time zone. Anyway USA vs Czech Republic so I'm shutting it down...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

4:03  AM Here
Can't Sleep LOL
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

 That was too Funny
:lol:
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Here is my Problem :
Tim Hortons Take Home Coffee



3 mugs in the morning
2 mugs in the afternoon
2 mugs in the evening

Stuff is addictive 
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

think i have a little bug   :P


Donkey

Quote from: hfheatherfox07 on January 02, 2013, 08:12:58 PM
Here is my Problem :
Tim Hortons Take Home Coffee



3 mugs in the morning
2 mugs in the afternoon
2 mugs in the evening

Stuff is addictive

Just woke up after staying up till nearly 5am watching the US kick the Czech Republic's arse. Had a buddy who drove a semi for Timmy's, used to get cases of coffee for free. The stuff is the crack cocaine of coffee, I'm completely at it's mercy.

Quote from: dedndave on January 03, 2013, 03:49:53 AM
think i have a little bug   :P



Weird, I didn't have any problems with it here at all.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

i am writing my own - lol
this is what i'm using for a test string...
szTest      db '1001000 1100101 1101100 1101100 01101111 100000 01001000011001010110000101110100011010000110010101110010',0

might be the leading 0 - i will play with it, later

jj2007

Dave,
01001000011001010110000101110100011010000110010101110010 is a 56-bit sequence - how do you want it to be interpreted?