AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Base 10 to Base 36 Conversion
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Raccoon



Joined: 02 Jan 2008
Posts: 70
Location: Freenode IRC

PostPosted: Tue Mar 11, 2008 10:05 am    Post subject: Reply with quote

Actually, I'm interested in this function because I'd like to modify it to use an arbitrary character table. Base 46 including all URL compatible "non-reserved' characters including the symbols " - _ . ! ~ * ' ( )

Consider how TinyURL or YouTube urls are constructed, but utilizing all of the valid symbols in a lookup table.
_________________
Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #autohotkey
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Tue Mar 11, 2008 2:07 pm    Post subject: Reply with quote

It is still just two lines for unsigned numbers
Code:
ToBase(n,b) {  ; n >= 0, 1 < b < StrLen(t), t = digits
   Static t := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~"
   Return (n < b ? "" : ToBase(n//b,b)) . SubStr(t,mod(n,b)+1,1)
}
Change the static variable t to contain your desired digits in order.
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed May 14, 2008 3:27 pm    Post subject: Reply with quote

OMG! Laszlo you rock!!!
i never imagine that base conversion can be done in just one line
totally amazing Shocked Shocked Shocked Shocked Shocked Shocked Shocked
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Guest






PostPosted: Thu May 15, 2008 2:54 am    Post subject: Reply with quote

heresy wrote:
i never imagine that base conversion can be done in just one line

It's just a translation of the elementary school routine you're already familiar with. You must have a relatively deep understanding of AHK to figure it out though.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group