Results 1 to 2 of 2

Thread: How to convert ascii into binary

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    delhi
    Posts
    22

    How to convert ascii into binary

    Hi,
    I want to know that how we can convert our ascii text into binary one.
    Pranav

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Use the KeyPress event of a text box to capture the KeyAscii of each typed character. Then do something like:

    VB Code:
    1. intAscii = KeyAscii
    2.  
    3. If intAscii > 128 then
    4.   strBinary = 1
    5.   intAscii = intAscii - 128
    6. Else
    7.   strBinary = 0
    8. End if
    9.  
    10. If intAcii > 64 Then
    11.   strBinary = strBinary & 1
    12.   intAscii = intAscii - 64
    13. Else
    14.   strBinary = 0
    15. End if
    16.  
    17. etc...

    or to shorten it up you can do:

    VB Code:
    1. intAscii = KeyAcii
    2. intCurrent = 128
    3.  
    4. For i = 1 to 8
    5.   If intAcii > intCurrent then
    6.     strBinary = strBinary & 1
    7.     intAcii = intAcii - intCurrent
    8.   Else
    9.     strBinary = strBinary & 0
    10.   End if
    11.   intCurrent = intCurrent / 2
    12. Next

    Hope this helps.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width