سؤال

I was wondering if it was possible to read a file bit meaning 0's and 1's and them displaying them, in either java or python. I don't know if it possible.

هل كانت مفيدة؟

المحلول

Yes, it is possible to read bits from bytes while knowing the endianness of the host system. That is, if you want an exact representation of the file.

import sys
sys.byteorder
open("fname").read(1)

if (ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN));
// Java reads and writes bytes pretty naturally, also.

You will need to use bitmasks to read the actual bits from the file.

نصائح أخرى

Sure, you read the file as byte stream (which you would typically do with a file), and then display the bytes in binary.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top