: i'm confused with & and AND. for eg:
 : >>> 1110 & 0110
 : 64
 : >>> 1110 and 0110
 : 72
 :  
 : i'm expecting if 1110 and with 0110 will get 0110 or 6. 
 : pls advise. 

Above, python thinks you are representing one number in decimal 
notation and the other in octal.

Decimal (no leading zeroes):
>>> 14 & 6
6

Binary (leading with '0b'):
>>> 0b1110 & 0b0110
6

Octal (leading with '0'):
>>> 016 & 006
6

Hexadecimal (leading with '0x'):
>>> 0xe & 0x06
6

Additionally, you will want to distinguish which operator you 
intend, bitwise or boolean.  It seems fairly clear that you are 
intending the bitwise operator if you are expecting '6' to be the 
answer.

  &       bitwise 'and'
  and     boolean 'and'

Read these three sections, at least, to understand the 
operators you are trying to use:

  
http://docs.python.org/reference/expressions.html#unary-arithmetic-and-bitwise-operations
  http://docs.python.org/reference/expressions.html#boolean-operations
  http://docs.python.org/reference/expressions.html#summary

This may also be useful:

  
http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex

Good luck,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to