C数据类型上的python按位操作?
在Python中是否可以对C数据类型执行位操作C数据类型上的python按位操作?,python,bit-manipulation,ctypes,Python,Bit Manipulation,Ctypes,在Python中是否可以对C数据类型执行位操作 Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes import c_uint8 >>> foo = c_uint8(4) >>>
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import c_uint8
>>> foo = c_uint8(4)
>>> foo << 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for <<: 'c_ubyte' and 'int'
>>>
Python2.7.1+(r271:868321911年4月11日18:13:53)
[GCC 4.5.2]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从ctypes导入c_uint8
>>>foo=c_uint8(4)
>>>福
这是可行的,但不是在C级别完成的:
foo.value << 1
foo.valueTryfoo.value或者Try int(foo)
foo.value <<= 1
from ctypes import c_uint8
foo = c_uint8(4)
print foo.value << 1
foo.value <<= 1