python - Python 中如何进行位运算?

标签 python c

Possible Duplicate:
How do I manipulate bits in Python?

这是我的代码:

int val = 0xAA;
int Bit, i;

for (i = 0; i < sizeof(Val)*8; i++) {
    Bit = 1<<i;    
    if (Val & Bit) {
        printf("Found a bit \n");
    }
}

我是 C 语言人员,我需要用 Python 来完成此操作。有人可以帮忙吗?

最佳答案

根据文档,您可以按照 C: 中的方式进行操作

5.4.1 Bitwise Operations on Integer Types

关于python - Python 中如何进行位运算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13995285/

相关文章:

Python:在 Pandas 中进行多列聚合

Python 2.6 -> Python 3(代理处理程序)

c++ - 为给定窗口遍历 MSAA 树的代码(Microsoft Active Accessibility)?在 C/C++ 中

c - win32 从 ListView 中检索所有选定项目的索引

c# - 使用 C# 进行 Ansi C 编程还是以 C# 方式编程?

c - 如何在 OS X C 代码中创建异步定时器?

python - 如何从 C 中读取 python pickle 数据库/文件?

python - 使用 RNN 对 keras 中的序列数据进行预测

python - QTableWidget + QPushButton 问题

c - C中数组指针的问题