sophisticate
Programmer
Hello!
I am wondering if anyone has been able to figure out how to do math beyond 31-bits and keep the variable type as an int. Here's the problem:
I'm working on an IPV4 class that allows binary manipulation of addresses. IP addresses are 32-bit (each a in a.a.a.a is an 8 bit number (256 possibilities)), so consequently, 31-bit numbers do not suffice. I can do the math with the BCMath module, but when I try to convert to binary format for printing or storage, I end up with 0111 1111 1111 1111 1111 1111 1111 1111. The only thing I can come up with is to separate both the original number and adder into 16- or 8- or 4- bits then combine them in a string for storage, but that's a massive headache and I don't have the endless supply of Advil it would require. So I was wondering if there was a more efficient way that anyone has found.
If my question is unclear, it's because it's 6am and I haven't made it to bed yet... but if you think you might know and just need some additional clarification, feel free to e-mail me.
Thanks,
brendanc@icehouse.net
I am wondering if anyone has been able to figure out how to do math beyond 31-bits and keep the variable type as an int. Here's the problem:
I'm working on an IPV4 class that allows binary manipulation of addresses. IP addresses are 32-bit (each a in a.a.a.a is an 8 bit number (256 possibilities)), so consequently, 31-bit numbers do not suffice. I can do the math with the BCMath module, but when I try to convert to binary format for printing or storage, I end up with 0111 1111 1111 1111 1111 1111 1111 1111. The only thing I can come up with is to separate both the original number and adder into 16- or 8- or 4- bits then combine them in a string for storage, but that's a massive headache and I don't have the endless supply of Advil it would require. So I was wondering if there was a more efficient way that anyone has found.
If my question is unclear, it's because it's 6am and I haven't made it to bed yet... but if you think you might know and just need some additional clarification, feel free to e-mail me.
Thanks,
brendanc@icehouse.net