any one on this binary ?

# Thread: any one on this binary ?

1. Dag
Junior Member
Join Date
Dec 1969
Posts
5

## any one on this binary ?

Hi all <BR>I have got a string of binary integers which needs to be looked up to a reference and its corresponding value from the other column should be shown as output. <BR> I have this reference table which gives me the mapping of binary integers corresponding to its character value.. <BR>If I have got a string like this "00111010001001110000111110010011000" <BR>each is a batch of 5 digits<BR>this has to be looked up in to the reference table which is like <BR><BR>bits char <BR>00000 a <BR>00001 b <BR>00010 c <BR>00011 d <BR>00100 e <BR>00101 f <BR>00110 g <BR>00111 h <BR>01000 i <BR>01001 j <BR>01010 k <BR>01011 l <BR>01100 m <BR>01101 n <BR>01110 o <BR>01111 p <BR>10000 q <BR>10001 r <BR>10010 s <BR>10011 t <BR>10100 u <BR>10101 v <BR>10110 w <BR>10111 x <BR>11000 y <BR>11001 z <BR>11010 2 <BR>11011 3 <BR>11100 4 <BR>11101 5 <BR>11110 6 <BR>11111 7 <BR><BR>So if my input will be "00111010001001110000111110010011000" my out put should be "hitq7ey" <BR>what would be the easiest way to do this??? This is actually base 32 conversion

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## DON'T REPOST SO SOON!

Stay with the original thread for AT LEAST a few hours...and when you repost, *say* you are doing so.<BR><BR>

3. New ASP Guest

## RE: any one on this binary ?

dim str, i, j, MYD<BR>dim strarray(100), fin(100)<BR><BR>str = "00111010001001110000111110010011000"<BR>MYD = 5<BR><BR>j = 1<BR>FOR i = 0 TO CINT(LEN(str))/MYD<BR> strarray(i) = MID(str,j, MYD)<BR> j = j + MYD<BR> SELECT CASE strarray(i)<BR> CASE "00000"<BR> fin(i) = "a"<BR> CASE "00001"<BR> fin(i) = "b"<BR>:<BR>:<BR> CASE "11111"<BR> fin(i) = "7"<BR> END SELECT<BR> Response.Write fin(i)<BR>NEXT<BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: any one on this binary ?

I normally don&#039;t post back to something like this, but your name prompted me to.<BR><BR>You&#039;re doing some unnecessary math (and let it be known, division is the biggest drag on the processor).<BR><BR>Instead of <BR><BR>FOR i = 0 TO CINT(LEN(str))/MYD<BR><BR><BR>why not<BR><BR>For i = 1 to Len(str) Step 5<BR><BR><BR>I didn&#039;t know if you knew about step or not, which prompted this post.<BR>

5. Senior Member
Join Date
Dec 1969
Posts
1,849

## RE: any one on this binary ?

Here is sort of the same deal, using how I explained it in the other thread using the select structure, and no array (adding characaters into a string)<BR><BR>chrstr = "00111010001001110000111110010011000" <BR>do while len(chrstr) &#062; 0 <BR> teststr = left(chrstr,5) <BR> chrstr = right(chrstr,len(chrstr)-5) <BR>SELECT CASE teststr<BR>CASE "00000"<BR>result = result & "a"<BR>CASE "00001"<BR>result = result & "b"<BR>:<BR>:<BR>CASE "11111"<BR>result = result & "7"<BR>END SELECT<BR>loop <BR>response.write(result) <BR>

6. New ASP Guest

## RE: any one on this binary ?

1. ONLY ONE DIV will NOT waste time. you can try it!!<BR>2. "For i = 1 to Len(str) Step 5 "<BR><BR>Will get array(1), array(6), array(11)...<BR>We should get array(0), array(1), array(2)...<BR><BR>Do you think locate bigger array will waste MEMORY ?<BR><BR><BR> <BR>

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh, well... Okay, why...

...do you need the two arrays strArray and fin ??? You don&#039;t use them for anything.<BR><BR>Oops! Also... Just noticed! You&#039;ll go one too far, as the code is written. Consider a string "00000". Len is 5. For i = 0 to Len(s)/5 ==&#062;&#062; For i = 0 to 1 !! OOPS! <BR><BR>So, to fix and simplify...<BR><BR>&#060;%<BR>dim str, i ,fin<BR>str = "00111010001001110000111110010011000"<BR>CONST MYD = 5<BR>fin = ""<BR><BR>IF Len(str) MOD MYD &#060;&#062; 0 Then<BR>&nbsp; &nbsp; Response.Write "Bad input string"<BR>&nbsp; &nbsp; Response.End<BR>End If<BR><BR>FOR i = 1 TO LEN(str) STEP MYD<BR>&nbsp; &nbsp; SELECT CASE Mid( str, i, MYD )<BR>&nbsp; &nbsp; CASE "00000"<BR>&nbsp; &nbsp; &nbsp; &nbsp; fin = fin & "a"<BR>&nbsp; &nbsp; CASE "00001"<BR>&nbsp; &nbsp; &nbsp; &nbsp; fin = fin & "b"<BR>&nbsp; &nbsp; :<BR>&nbsp; &nbsp; :<BR>&nbsp; &nbsp; CASE "11111"<BR>&nbsp; &nbsp; &nbsp; &nbsp; fin = fin & "7"<BR>&nbsp; &nbsp; END SELECT<BR>NEXT<BR>Response.Write fin<BR>%&#062;<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## What is the array for???

What possible use is *either* array, in any case???

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: any one on this binary ?

1. Not waste time. It will. Not on one test machine, but pretend to multiply that by thousands of users. For this case you may be right.<BR><BR>2. There is no array. I started it at 1 because you were looping through the length of a string, and in VBScript, strings start at 1.<BR><BR><BR>I am sorry I upset you. I seen your name as "New ASP", and figured I should point out that there is a Step in a for loop. I didn&#039;t know you were already aware.<BR><BR>Please accept my apology, and I will never respond to your posts again.

10. New ASP Guest

## RE: any one on this binary ?

NO apology ! Everyone can point my bad code & is my teacher:)<BR><BR>How about this time ?<BR><BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;%OPTION EXPLICIT%&#062;<BR>&#060;%<BR>DIM str, str_f, str_temp<BR>DIM i, j, k, MYD<BR><BR>str = "00111010001001110000111110010011000"<BR>MYD = 5<BR>k = CINT(LEN(str))/MYD<BR>j = 1<BR><BR>FOR i = 0 TO k<BR><BR>SELECT CASE MID(str,j, MYD)<BR>CASE "00000"<BR>str_f = str_f & "a"<BR>CASE "00001"<BR>str_f = str_f & "b"<BR>:<BR>:<BR>CASE "11111"<BR>str_f = str_f & "7"<BR>END SELECT<BR>j = j + MYD<BR><BR>Response.Write str_f<BR><BR>NEXT<BR>%&#062;<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
•