X
xkenneth
Why is 3500 | -67 equal to 3500 instead of -3567?
xkenneth said:Why is 3500 | -67 equal to 3500 instead of -3567?
xkenneth said:Why is 3500 | -67 equal to 3500 instead of -3567?
Tim said:I also wonder if it wouldn't be faster to put the numbers into a list
and join the list into a string -- did you test with that?
Hello,
I've written a little (optimized) method to get a bit-string:
def bitstringneg(number, digits=32):
"""optimized for negative numbers"""
result = ""
for a in xrange(digits):
if number & 1:
result += '1'
else:
result += '0'
number >>= 1
return result
def bitstringpos(number):
"""optimized for positive numbers"""
result = ""
while number:
if number & 1:
result += '1'
else:
result += '0'
number >>= 1
return result
def bitstring(number, digits=32):
"""lsb------>msb"""
result = ""
if number < 0:
return bitstringneg(number, digits)
else:
return bitstringpos(number)
BTW: Is there something like a sizeof() method for int numbers?
Mh, that doesn't do what i want. I'd like to have something like:Adam said:import struct
help( strict.calcsize )
Why one bit at a time?
Cheers - Adam
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.