The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
The situation is that I would essentially like to pass around 70 boolean variables via GET in php to a webpage. Now, rather than actually using 70 different variables, which would make a ludicrously long url, I'd like to use bit flags to pass them all as one integer. Of course, 2^70 seems too large to be in the scope of what I'm used to handling. So, what I want to ask is if there's a way to (easily enough) convert a 70-digit binary number to an integer, then converted back to binary to extract each value.
Note that I do not want to use php sessions or forms to pass these values, because I want to be able to do this strictly by url.
So I have zero PHP experience so I probably should not be replying, but is there any way you can cast the bits to a character? You would end up with 9 characters (2 extra bits that would never be assigned based on your boolean values).
BlazeFire on
0
Seguerof the VoidSydney, AustraliaRegistered Userregular
edited December 2010
You could always convert it to another base, that's possibly more compact (hex, oct?)
Essentially, the user will choose which of ~70 objects will appear on a particular page, preferably through URL so it can be linked. So for each object, its either there, or it isn't. 2^70 combinations. Ideally, I wanted to convert the string of 1's and 0's to an integer, to be converted back to binary in order to read off the 1's and 0's again, but of course these are very large numbers to work with for integers. What I was wondering is if there was an easy enough way to do this, say, by variable type. It seems as though there's not, however I think some of the ideas here will help be accomplish what I want to.
I highly doubt this is the best way to accomplish what I want, but it seems to work.
Thanks for the replies.
AgentBryant on
0
Seguerof the VoidSydney, AustraliaRegistered Userregular
edited December 2010
Alright I'd say a bitmask is not what you want here.
Unless you're on a 64 bit system, the Integer will be too small I believe, to handle a 2^70 binary number being converted (hell, can 64 bit handle it?)
Don't worry about all the ones that are off, or all the ones that are on.
Choose one (or even have it be dynamic!) and do something like this:
Posts
we also talk about other random shit and clown upon each other
http://php.net/manual/en/function.base64-encode.php
URLs can only contain so many characters in them, which is why he really needs a compact conversion.
Some sort of codec would be best here (one that outputs a URL friendly string)
70 numbers, not 2^70.
This tripped me up.
It's not 70 numbers, it is a
Which can either mean 70 0s and 1s, or 70x however many bits he is using.
If it is 8bit, 70x8 = 560 0s and 1s.. which is a huge decimal number (1.1793632577567317e+167)
Now that I think about it, the 70th variable IS going to 2^70 (or can be)
AgentBryant: could you provide more context? Maybe there is a better way to do what you are trying to do.
Here's how it would work with 24 bits, but can be any amount
Bitmask: 010000010100000101000001
Base64 encode that sucker: QUFB
Make URL: www.AgentBryantsFancySite.com?data=QUFB
Base64 decode QUFB: 010000010100000101000001
Voila! Large bitstream passed via url.
That said, like Seguer mentioned it feels like there might be a better way.
I highly doubt this is the best way to accomplish what I want, but it seems to work.
Thanks for the replies.
Unless you're on a 64 bit system, the Integer will be too small I believe, to handle a 2^70 binary number being converted (hell, can 64 bit handle it?)
Don't worry about all the ones that are off, or all the ones that are on.
Choose one (or even have it be dynamic!) and do something like this:
item : id
item1 : 1
item2 : 2
...
item69 : 69
item70: 70
blah.php?data=1,2,6,12,45,78,34,12&state=on
That way you can use state = off, if there are more "on" than "off" to have a shorter URL (potentially)
You may want to be using arrays here too at some point, depending on how you've setup these objects and your data.
If you really wanted to you could still base64 encode that data parameter