Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript: ASCII to Binary

Posted on 2004-08-13
4
Medium Priority
?
2,173 Views
Last Modified: 2008-12-04
I'm searching for a function to convert an ascii character to binary.

For example, I have this character: @

I want to convert it to: 01000000

does anyone know where I can find code to do this? It has to be regular VB script, I can't load any kind of components or use any .net stuff to do this.
0
Comment
Question by:WebArchitect_Vince
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Rodney Helsens
ID: 11793855
IS this what you are looking to do?

http://www.motobit.com/tips/detpg_BinASP.htm
0
 
LVL 9

Expert Comment

by:Rodney Helsens
ID: 11793940
This seems to work too..

<%

Function cBIN(iC)
cBIN = ""
X = 256
For Y = 1 To 8
     bC = 0
     X = X / 2
     If iC >= X Then
     bC = 1
     iC = iC - X
     End If
   cBIN = cBIN & bC
Next
End Function

Response.Write ( cBIN(Asc("@")) )

%>
0
 
LVL 15

Accepted Solution

by:
deighc earned 2000 total points
ID: 11793988
Try this. You need to pass both the character and the length of the string you want returned (8 chars in your example:

decVal = DecToBin("@", 8)

Function DecToBin(strChar, len)
  dim strResult
  dim intValue
  dim intExp
  dim intDec
 
  intDec = Asc(strChar)
  strResult = ""

  intValue = intDEC
  intExp = 2 ^ (len - 1)
  while intExp >= 1
    if intValue >= intExp then
      intValue = intValue - intExp
      strResult = strResult & "1"
    else
      strResult = strResult & "0"
    end if
    intExp = intExp / 2
  wend

  DecToBin = strResult
End Function
0
 
LVL 15

Expert Comment

by:deighc
ID: 11794003
... and maybe a better function name would be "charToBinary" ....
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question