Reputation: 10204
I would like to see 0s and 1s in the binary code.
Say I compile a C code to a.out, cat a.out
does not show the raw date but seems to display it as if it were ASCII code. What is the right way to see 0s and 1s?
Upvotes: 0
Views: 48
Reputation: 4291
That depends on the tool you want to use. If you are comfortable with writing your own (for example in C) it would go something like this:
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);
}
Enter formatting as needed.
Upvotes: 1