layer Posted March 10, 2005 Posted March 10, 2005 (edited) im just making a function... and for some reason =/ its always returning 0... heres the code Func Text2Binary($text) $letters= StringSplit("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",") $split= StringSplit("01100001,01100010,01100011,01100100,01100101,01100110,01100111,01101000,01101001,01101010,011010 11,01101100,01101101,01101110,01101111,01110000,01110001,01110010,01110011,01110100,01110101,0111011 0,01110111,01111000,01111001,01111010", ",") For $i = 1 to $letters[0] $out= StringReplace($text, $letters[$i], $split[$i]) Next Return $out EndFunc $text2bin= Text2Binary("testing") MsgBox(0, "Text2Binary", Text2Binary($text2bin)) Func Binary2Text($binary) $letters= StringSplit("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",") $split= StringSplit("01100001,01100010,01100011,01100100,01100101,01100110,01100111,01101000,01101001,01101010,011010 11,01101100,01101101,01101110,01101111,01110000,01110001,01110010,01110011,01110100,01110101,0111011 0,01110111,01111000,01111001,01111010", ",") For $i = 1 to $split[0] $out= StringReplace($binary, $split, $letters) Next Return $out EndFunc $bin2text= Binary2Text("01100001,01100010") MsgBox (0, "Binary2Text", Binary2Text($bin2text)) maybe it could be coded better, but to me, what ever gets the job done, works, so does anyone have any clue as to why this is always returning 0...? thanks! Edited March 10, 2005 by layer FootbaG
layer Posted March 10, 2005 Author Posted March 10, 2005 oops, i think i found the problem.. quite obvious actually, hang on and ill check ! FootbaG
jpm Posted March 10, 2005 Posted March 10, 2005 im just making a function... and for some reason =/ its always returning 0... heres the codeFunc Text2Binary($text) $letters= StringSplit("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",") $split= StringSplit("01100001,01100010,01100011,01100100,01100101,01100110,01100111,01101000,01101001,01101010,011010 11,01101100,01101101,01101110,01101111,01110000,01110001,01110010,01110011,01110100,01110101,0111011 0,01110111,01111000,01111001,01111010", ",") For $i = 1 to $letters[0] $out= StringReplace($text, $letters[$i], $split[$i]) Next EndFunc MsgBox(0, "Text2Binary", Text2Binary("testing"))maybe it could be coded better, but to me, what ever gets the job done, works, so does anyone have any clue as to why this is always returning 0...? thanks! <{POST_SNAPBACK}>your function as no explicit return so the implicit return is 0You have to have an return something if you want something different from 0
layer Posted March 10, 2005 Author Posted March 10, 2005 (edited) nevermind... doesnt work, heres the full code though..Func Text2Binary($text) $letters= StringSplit("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",") $split= StringSplit("01100001,01100010,01100011,01100100,01100101,01100110,01100111,01101000,01101001,01101010,011010 11,01101100,01101101,01101110,01101111,01110000,01110001,01110010,01110011,01110100,01110101,0111011 0,01110111,01111000,01111001,01111010", ",") For $i = 1 to $letters[0] $out= StringReplace($text, $letters[$i], $split[$i]) Next Return $out EndFunc $text2bin= Text2Binary("testing") MsgBox(0, "Text2Binary", Text2Binary($text2bin)) Func Binary2Text($binary) $letters= StringSplit("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",") $split= StringSplit("01100001,01100010,01100011,01100100,01100101,01100110,01100111,01101000,01101001,01101010,011010 11,01101100,01101101,01101110,01101111,01110000,01110001,01110010,01110011,01110100,01110101,0111011 0,01110111,01111000,01111001,01111010", ",") For $i = 1 to $split[0] $out= StringReplace($binary, $split, $letters) Next Return $out EndFunc $bin2text= Binary2Text("01100001,01100010") MsgBox (0, "Binary2Text", Binary2Text($bin2text))not sure in Binary2Text would work even if the code were right... so any suggestions? thanks!EDIT: hey thanks jpm! ill give it a try! you responded as i was typing EDIT2: ok, Text2Binary works! thanks a million jpm, but Binary2Text doesnt i updated the code in this post... i dont think it may even be possible because theres only 0's and 1's where as the alphabet has all different letters, not just a and b... Edited March 10, 2005 by layer FootbaG
layer Posted March 10, 2005 Author Posted March 10, 2005 actually, it doesnt work... oh well... it returns testing, but it should return testing in binary..! geez, Text2Binary! FootbaG
SlimShady Posted March 10, 2005 Posted March 10, 2005 (edited) I'm gonna fix it for you. But promise me that you'll study the code. Edit: I attached the working script. Edited March 10, 2005 by SlimShady
layer Posted March 11, 2005 Author Posted March 11, 2005 thanks Slim! heres what i came out with, edited with your additions, but first, ill just say what i changed and why 1.) $out must = $text because that's what your returning, so $out = $text means your returning the text, that was replaced by binary... 2.) Same applies for $out = $binary 3.) I didn't have any [$i] arrays in $split and $letters in the Binary2Text... 4.) Changed: $bin2text= Binary2Text("01100001,01100010") MsgBox (0, "Binary2Text", Binary2Text($bin2text)) to $bin2text = Binary2Text($text2bin) MsgBox (0, "Binary2Text", $bin2text) so that you could get the translated "testing" to binary, and then convert it back to text... 5.) and i think that pretty much wraps it up, don't you? thanks a million Slim! FootbaG
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now