blindwig Posted March 9, 2006 Share Posted March 9, 2006 (edited) I'm working on optimizing a base64 conversion routine and I go the idea that I can use a BinaryString() function call instead of doing lots of Chr() functions. I was also hoping that I could use the int() and/or Number() functions instead of asc() functions.This code:$i = ((65 * 256 + 66) * 256 + 67) * 256 + 68 $b = BinaryString($i) $n = Number($b) ConsoleWrite($i & @CR) ConsoleWrite($b & @CR) ConsoleWrite($n & @CR)Outputs this:1094861636 DCBA 68(FYI: Chr(65)='A')First, I notice that BinaryString() puts the bytes in reverse order. This isn't a bug, as this is the way that the function is described in the manual. I'm just curious as to why it would do this - what's the purpose of reversing the bytes?Second, why does the Number() function only consider the first byte of the BinaryString? The statment "Number(string(256*256*256*256))" works as expected, so obviously the Number() function is capable to handle numbers bigger than 8 bits?And one more thing - BinaryString() always returns a string that is a multiple of 4. So the statement "StringLen(BinaryString(65))" evaluates to 4. Why is this? Agagin, this is not a bug, it is in the manual, but I just want to know why. Edited March 9, 2006 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted March 11, 2006 Author Share Posted March 11, 2006 I've also posted a thread to the Bug Reports forum. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
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