need the unsigned value from dl.call()
I'm using dl.call() to call a C function in an external library. It's working great so far except for one function, which returns an unsigned int in the C version. However, in python it returns a signed value to me. How can I get the unsigned value from this? I haven't brushed up on my two's complement in a while, so I was hoping someone could give me a hand. Thanks eliss -- http://mail.python.org/mailman/listinfo/python-list
Re: need the unsigned value from dl.call()
On Dec 11, 12:38 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > Larry Bates wrote: > > >> eliss wrote: > >>> I'm using dl.call() to call a C function in an external library. It's > >>> working great so far except for one function, which returns an > >>> unsigned int in the C version. However, in python it returns a signed > >>> value to me. How can I get the unsigned value from this? I haven't > >>> brushed up on my two's complement in a while, so I was hoping someone > >>> could give me a hand. > > >>> Thanks > > >>> eliss > >> It is returning 32 bits. If the sign bit (bit 32) is on it appears as a > >> negative number. Test for negative and multiply the absolute value * 2. > >> That should get you the unsigned value you want in a long. > > > Erm... Nope. > > > All bits set is -1 - so according to your recipe, that would be abs(-1) * 2 > > = 2 > > > I'd suggest this formula: > > > if value < 0: > > value = 2^32 + value + 1 > > > Diez > > Thanks for the correction. You are of course correct. > > -Larry Hi thanks for the responses but I'm afraid I don't see how either formula works. Lets say I get the return value of -5, which is 1011b when it should be 11. Then according to the formula it would be 2^4-5+1=12 But it should be 11... -- http://mail.python.org/mailman/listinfo/python-list
Re: need the unsigned value from dl.call()
On Dec 11, 2:28 pm, eliss <[EMAIL PROTECTED]> wrote: > On Dec 11, 12:38 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > > > > > Diez B. Roggisch wrote: > > > Larry Bates wrote: > > > >> eliss wrote: > > >>> I'm using dl.call() to call a C function in an external library. It's > > >>> working great so far except for one function, which returns an > > >>> unsigned int in the C version. However, in python it returns a signed > > >>> value to me. How can I get the unsigned value from this? I haven't > > >>> brushed up on my two's complement in a while, so I was hoping someone > > >>> could give me a hand. > > > >>> Thanks > > > >>> eliss > > >> It is returning 32 bits. If the sign bit (bit 32) is on it appears as a > > >> negative number. Test for negative and multiply the absolute value * 2. > > >> That should get you the unsigned value you want in a long. > > > > Erm... Nope. > > > > All bits set is -1 - so according to your recipe, that would be abs(-1) * > > > 2 > > > = 2 > > > > I'd suggest this formula: > > > > if value < 0: > > > value = 2^32 + value + 1 > > > > Diez > > > Thanks for the correction. You are of course correct. > > > -Larry > > Hi thanks for the responses but I'm afraid I don't see how either > formula works. > > Lets say I get the return value of -5, which is 1011b when it should > be 11. Then according to the formula it would be 2^4-5+1=12 > > But it should be 11... Seems like the simple formula of: if value < 0: value = 2^32 + value might just work. Thanks :) -- http://mail.python.org/mailman/listinfo/python-list
reliable whois in python
Hi everyone, I'm trying to write a python script to whois a few domains twice a day so I get notified when they become available. I did it 2 ways, but neither way is very reliable, so I'm asking here. 1) I tried just calling "whois %s" using popen, but I found that once every few weeks, I get errors like: connect: No route to host OR fgets: Connection reset by peer I don't think it's a connectivity issue because looking up the other domains that day works, and just one domain will give an error. So it's probably more like a networking issue? I don't know... 2) I tried using sockets to connect to the whois port of whois.internic.net and then read the info, which works a little better than 1). However, sometimes this is not reliable too and I get errors. Does anyone have any ideas how I can do this better? Thanks, eliss -- http://mail.python.org/mailman/listinfo/python-list
