ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → C / C++
static int next_bit_BE(int input) {
static unsigned char byte;
static unsigned int bits = 0;
if (bits == 0) {
if (!read(input, &byte, 1)) return -1;
bits=8;
}
int bit = (unsigned char)(byte & 0x80) >> 7;
byte = (unsigned char)byte << 1;
bits--;
return bit;
}
int next_code_BE(int input, int code_length) {
code = 0;
for (int i=0; i<code_length; i++) {
int bit = next_bit_BE(input);
if (bit == -1) break; // done
code = (code<<1) | bit;
}
return code;
}
(nicht getestet)
Daniel Marschall
ViaThinkSoft Co-Founder
ViaThinkSoft Co-Founder