On 2005-08-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > i have an ascii string comming in the serial port and i need to convert > it to something else, like an integer, or binary, or even a hex so i > can use the bitwise comparison on it.
But what do you mean by "integer", "binary", and "hex"? Decimal, hex, and binary are all representations of integers. On your computer all integers are 2's compliment binary (we're going to ignore BCD for the moment). The only thing that can be "decimal" or "hex" are _string_ representations of integer values. If you want something upon which you can perform the bitwise boolean operations &, ^, |, then you most probably just want an integer object. To convert a string to an integer, use the int() builtin passing it the string an an optional base: >>> int("1234") 1234 >>> int("1234",10) 1234 >>> int("0x100",16) 256 >>> int("100",16) 256 >>> int("100",2) 4 Others have already shown you how to use the bitwise boolean operators. -- Grant Edwards grante Yow! Look DEEP into the at OPENINGS!! Do you see any visi.com ELVES or EDSELS... or a HIGHBALL??... -- http://mail.python.org/mailman/listinfo/python-list