Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C数据类型上的python按位操作?_Python_Bit Manipulation_Ctypes - Fatal编程技术网

C数据类型上的python按位操作?

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中是否可以对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)
>>> 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.valueTry
foo.value或者Try int(foo)
foo.value <<= 1
from ctypes import c_uint8
foo = c_uint8(4)
print foo.value << 1
foo.value <<= 1