Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 86,251 VB Programmers. There are 2,135 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Convert Ascii to Char

 
Reply to this topicStart new topic

Convert Ascii to Char, To Convert Bulk amount of Ascii Array to Char

hisham123
post 8 May, 2008 - 09:43 PM
Post #1


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 1



'bdata is byte array in which i had 150,000 Ascii Codes.This is from after decrypt 'i am getting in ascii code and assign to bdata (byte array)

vb
for i= 1 to ubound(bdata)
str= str + Asc(bdata(i))
Next


'It takes near 6 minutes, i had to minimize the time with alternative code
'could anbody help in this code

with regards

Hisham
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


born2c0de
post 10 May, 2008 - 12:39 AM
Post #2


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,298

QUOTE
str= str + Asc(bdata(i))

How can VB even compile this statement?
Str() is a function, you can't use a variable with the same name.

You can however, use certain techniques to ensure that your program works slightly faster and doesn't crash.
  • Add DoEvents in your code like this:
    vb
    for i= 1 to ubound(bdata)
    DoEvents
    strx= strx + str(Asc(bdata(i)))
    Next

    This allows Windows to process other messages while your loop is executing. Without DoEvents, Windows waits for the Procedure to complete (which means loop has to complete first), and if your loop takes a long time, your program might hang or appear to have crashed.
  • I forgot what this technique is called but it will make your loop slightly faster. If you have to operate on 100 ASCII Values, the usual method would be:
    vb
    For i = 1 to 100
    strx = strx + str(Asc(bdata(i)))
    Next


    An optimized version would look like this:
    vb
    For i = 1 to 10
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    strx = strx + str(Asc(bdata(i)))
    Next

    Instead of performing 1 operation 100 times, perform 10 operations consecutively 10 times.

    This is faster because of the way the six-stage instruction pipeline works. I'd love to explain this in a nutshell, but to appreciate the increase in speed, you would need to know the entire thing (which would make this post a lot lot longer) so refer to Computer Organisation and Architecture by William Stallings for a detailed explanantion about Instruction Pipelines.

    Long story cut short, the Instruction cycle is designed in such a way that consecutive instructions are executed faster than instructions with branches. (Refer Locality of Reference from the same book)

    So avoiding a lot of branching will increase your speed noticeably for larger loop increments.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

lakhanmahajan
post 10 May, 2008 - 10:54 AM
Post #3


New D.I.C Head

*
Joined: 4 May, 2008
Posts: 13

QUOTE(hisham123 @ 8 May, 2008 - 09:43 PM) *

'bdata is byte array in which i had 150,000 Ascii Codes.This is from after decrypt 'i am getting in ascii code and assign to bdata (byte array)

vb
for i= 1 to ubound(bdata)
str= str + Asc(bdata(i))
Next


'It takes near 6 minutes, i had to minimize the time with alternative code
'could anbody help in this code

with regards

Hisham


I am not understand your que
But you can use this code to convert ascii into char
CODE

MsgBox (Chr$(value))
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 09:00AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month