converting hex to binary

Results 1 to 2 of 2

Thread: converting hex to binary

  1. #1
    lissy Guest

    Default converting hex to binary

    hi all<BR> is there a way to convert a string in hexadecimal to binary in vbscript..<BR>eg. If i want to convert 3a270f93(in hex format) to 00111010001001110000111110010011<BR>including the leading zero&#039;s how do i do it??<BR>thx in advance..

  2. #2
    Join Date
    Dec 1969

    Default RE: converting hex to binary

    There are *MANY MANY* ways to do this!<BR><BR>The *general* way would be to convert *any* number to internal format and then convert the internal format back out using *any* base (e.g, if you wanted the answer in base 3, or base 12, or base 8, it is no more work to do that then to make one specially for binary). But the general way isn&#039;t really very efficient, so if you want to write an efficient routine, how about this one:<BR><BR><BR>&#060;%<BR>binVals = Array("0000","0001","0010","0011","0100","0101","0 110","0111", _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "1000","1001","1010","1011","1100","1101","1110"," 1111" )<BR>...<BR>strHex = "3a270F93"<BR>strBin = ""<BR>For i = 1 To Len(strHex)<BR>&nbsp; &nbsp; digit = CInt( "&H" & Mid( strHex, i, 1 ) )<BR>&nbsp; &nbsp; strBin = strBin & binVals( digit )<BR>Next<BR>...<BR>%&#062;<BR><BR><BR>

Posting Permissions

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