ngskicker Posted February 23, 2010 Posted February 23, 2010 (edited) i have this code Func ($Binary) $Decimal = 0 For $i = 1 To StringLen($Binary) $Decimal = 2^($i-1) * StringMid($Binary, StringLen($Binary)+1-$i,1) + $Decimal Next Return $Decimal EndFunc to convert binary number to decimal and this code Func DecConvert($Decimal) $n = "" $Symbols = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" While $Decimal > 61 $m = Mod($Decimal ,63) $m = StringMid($Symbols,$m,1) $n = $m & $n $Decimal = int($Decimal / 62) WEnd If $Decimal > 9 Then $Decimal = StringMid($Symbols,$Decimal,1) EndIf Return($Decimal & $n) EndFunc to convert Decimal to base 62 can someone help me to cobine 2 process above, instead of convert to decimal then convert to base 62 also maybe someone can give the code to convert it back from base 62 to binary Edited February 23, 2010 by ngskicker
omikron48 Posted February 23, 2010 Posted February 23, 2010 (edited) Wow. Is it just me or am I noticing a trend with your topics... Code for me please? If you took time to understand what the code does, it should be fairly simple to make a reverse process, considering that this is just number conversion to different bases and all that. Edited February 23, 2010 by omikron48
Negative1 Posted February 23, 2010 Posted February 23, 2010 (edited) $Binary = "1111" ;example $Decimal = 0 For $i = 1 To StringLen($Binary) $Decimal = 2^($i-1) * StringMid($Binary, StringLen($Binary)+1-$i,1) + $Decimal Next $n = "" $Symbols = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" While $Decimal > 61 $m = Mod($Decimal ,63) $m = StringMid($Symbols,$m,1) $n = $m & $n $Decimal = int($Decimal / 62) WEnd If $Decimal > 9 Then $Decimal = StringMid($Symbols,$Decimal,1) EndIf MsgBox(0,"",$Decimal) Untested but seams like all you have to do is trim the func tags out to go first to decimal then to base62. Good luck from here -1 Edited February 23, 2010 by Negative1 What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.
ngskicker Posted February 23, 2010 Author Posted February 23, 2010 (edited) i try to build some aplication for my colege task that convert much text charachter to a small size char based on huffman coding. huffman coding return a loooooong binary string, so i decide to convert it to binary number than convert it to base 62 char that more sorten, 4 digit binary can be converted to 1 digit base 16 so i think maybe 8 digit or more can be converted to 1 digit base 62, but im stuck with this and if i use my first code if i convert 100100000110001000101001110001000011001000010100011001000011000010 binary the result is 4.16156960472392e+019 instead of 41615696047239180000 sory for my bad english Edited February 23, 2010 by ngskicker
Negative1 Posted February 23, 2010 Posted February 23, 2010 i try to build some aplication for my colege task that convert much text charachter to a small size char based on huffman coding.huffman coding return a loooooong binary string, so i decide to convert it to binary number than convert it to base 62 char that more sorten, 4 digit binary can be converted to 1 digit base 16 so i think maybe 8 digit or more can be converted to 1 digit base 62, but im stuck with thisand if i use my first code if i convert 100100000110001000101001110001000011001000010100011001000011000010 binary the result is 4.16156960472392e+019 instead of 41615696047239180000sory for my bad english4.16156960472392e+019 is the correct answer What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.
ngskicker Posted February 23, 2010 Author Posted February 23, 2010 (edited) 4.16156960472392e+019 is the correct answerno can you notice that 4.16156960472392e+019 > 41615696047239180000 Edited February 23, 2010 by ngskicker
omikron48 Posted February 23, 2010 Posted February 23, 2010 That the precision error telling you to notice it. The data type is too small to store the value that you want.
jchd Posted February 24, 2010 Posted February 24, 2010 huffman coding return a loooooong binary string, so i decide to convert it to binary number than convert it to base 62 char that more sorten, 4 digit binary can be converted to 1 digit base 16 so i think maybe 8 digit or more can be converted to 1 digit base 62, but im stuck with thisYou're running on a Moebius strip there.Do you mean the base-62 representation is shorter than binary? Seriously?Ask yourself how many bits are needed to encode a single base-16 digit (which encodes a 4-bit nibble). Umm?You won't compress over Huffman this way. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
ngskicker Posted February 24, 2010 Author Posted February 24, 2010 (edited) You're running on a Moebius strip there.Do you mean the base-62 representation is shorter than binary? Seriously?Ask yourself how many bits are needed to encode a single base-16 digit (which encodes a 4-bit nibble). Umm?You won't compress over Huffman this way.hmm...i dont mind with bits guys, ok if you dont know my mind...if i write 100100000110001000101001110001000011001000010100011001000011000010 in inputbox that have max input 60 char, sure it will not fit, but if i convert it to decimal 41615696047239180000, looks 66 Charachter Vs 20 Charachter, i am newbie but since 3 days ago i have learn huffman coding, i dont mind to store data in computer, i just want to write it in a short, and please JUST HELP ME WITH THIS F*CKING BINARY TO BASE 62 code if you wish,and sory about my bad gramar Edited February 24, 2010 by ngskicker
omikron48 Posted February 24, 2010 Posted February 24, 2010 (edited) JUST HELP ME WITH THIS F*CKING BINARY TO BASE 62 code if you wishDon't think anyone's gonna be wishing to help after that one... Edited February 24, 2010 by omikron48
ngskicker Posted February 24, 2010 Author Posted February 24, 2010 cmon guys, i need help in converting binary to base 62, i have 2 script for your reference, in first post
PsaltyDS Posted February 24, 2010 Posted February 24, 2010 I'm not coding it for you, since you don't seem interested in learning anything, just getting someone to do it for you. But why BASE62? It doesn't fall on an even binary boundary. BASE64 (add two more symbols) would simply be 6-bit groups (as Hex is 4-bit). It would be easier to code and would run much faster than a BASE62 conversion would. Packing is still an issue. The reason Hex is used everywhere and Octal (3-bit groups) is used almost nowhere anymore, is the packing efficiency with real world hardware. Symbols that represent 3-bit (Octal), or 6-bit (Base64) groups can't use an integer number of symbols to represent 8-bit, 16-bit, 32-bit, and 64-bit values. Hex can represent them all with 2, 4, 8, or 16 symbols, with no bits left over. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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