Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Algorithm

Author
Message
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Jun 2003 15:36 Edited at: 20th Jun 2003 15:40
Does anyone know of a good (ie fast and small) to convert a 16 character text string (which can have ASCII1 to ASCII255 in it) to a 16-bit number between 0 and 65535 ?

The only way I can think of doing it is taking a group of say, 4 characters and multiplying the ASCII value of each by 0.0039 (1/255) and the 4 values together, make an integer and the shift left or right according to where in the bitfield I want it.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Jun 2003 16:02 Edited at: 20th Jun 2003 16:19
It depends on the the range of characters that you need, or if you're talking a lossy-type compression.

I remember that PsionII's had a method that used 6 bits for each character (giving 64 characters)
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Jun 2003 16:35
Its not actually for compression - its to remove the need for seaching 64K worth of arrays - its a lot quicker going directly to relevant index than having to do a seach (even if it is two way).

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Jun 2003 00:27
Try this one:



I've adapted it from a 32 bit algorithm. It seems to give fairly well distributed results in the small sample of works I gave it, but I suspect you'll still need to deal with collisions in your array.
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 21st Jun 2003 01:49 Edited at: 21st Jun 2003 15:39
Thanks Ian - that'll be very useful for my array plug-in.
As for collisions - if they find two strings use the same structure, then tough - a different name will have to be chosen...

I've converted it to C - works very well.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!

Login to post a reply

Server time is: 2024-11-23 07:51:47
Your offset time is: 2024-11-23 07:51:47