left shift
- From: "devnew@xxxxxxxxx" <devnew@xxxxxxxxx>
- Date: Mon, 22 Oct 2007 09:37:10 -0000
hi
i am relatively new to python..was checking out some bit shifting..
when i do
255<< 24 i get 4278190080
whereas in java or c it gives -16777216
can someone tell me why this is ?,what should i do if i want the
output as -16777216 ?
dn
p:s
I wrote a fn to show the binary digits in the number and it gives same
output for both numbers(4278190080 and -16777216)
def pBinInt(str,i):
print str,",int",i,", binary:"
print " ",
for j in range(31,-1,-1):
if(((1 << j) & i) != 0):
print 1,
else:
print 0,
print ""
#example usage pBinInt("255",255)
.
- Follow-Ups:
- Re: left shift
- From: Ulrich Eckhardt
- Re: left shift
- From: Daniel Dyer
- Re: left shift
- Prev by Date: Re: Great SWT Program
- Next by Date: Re: left shift
- Previous by thread: Drag and Drop and Generate Graphic
- Next by thread: Re: left shift
- Index(es):
Relevant Pages
|
|