?
Solved

VBScript: ASCII to Binary

Posted on 2004-08-13
4
Medium Priority
?
2,125 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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