如何从一段二进制代码中获取 0 和 1?

How to get the 0s and 1s from a piece of binary code?

我想在二进制代码中看到 0 和 1。

假设我将 C 代码编译为 a.out,cat a.out 不显示原始日期,但似乎将其显示为 ASCII 代码。 0 和 1 的正确查看方式是什么?

这取决于您要使用的工具。如果您愿意自己编写(例如在 C 中),它会是这样的:

if (FILE *fp = fopen("fileToOpen", "rb"))
{
    uint8_t buffer[4096];
    int32_t readBytes;
    while (0 < (readBytes = fread(buffer, 1, sizeof(buffer), fp))
    {
        for (int32_t i = 0; i < readBytes; ++i)
        {
            for (int32_t j = 0; j < 8; ++j)
                printf("%d", (buffer[i]&(1 << j)) ? 1 : 0;
            printf(" ");
        }
    }
    fclose(fp);
}

根据需要输入格式。