문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top