Question

I've never wandered into reading binary data before. I'm trying to learn now, and make a simple application to read the header data from a FLAC file and display the information in human readable format.

As a first, given that the first bit of data I'm interested in is 0x10000100, how do I use C# to read the first bit (1) and then read the int value stored in the subsequent 7 bits? I know already how to read the byte into a byte array using binaryreader... Just don't know how to parse this data in code.

Thanks in advance.

Was it helpful?

Solution

Binray "and" &, "or" |, "not" ~ are used to extract bits.

Here is approximate code:

byte value = 0x84;
bool flag = (value & 0x80) != 0;
var intPart = value & ~0x80;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top