Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,26 @@ class bit_extract {
unsigned r = 0;
unsigned count_bits = 0;
while (bits >= bits_in_byte) {
r |= *p++ << count_bits;
// The region we're extracting extends to the end of the byte
// we're scanning; extract what's remaining, and add it to
// the result (after shiting it into the correct position)
r |= *p++ << (bits - bits_in_byte);
count_bits += bits_in_byte;
bits -= bits_in_byte;
bits_in_byte = 8;
}
if (bits > 0) {
unsigned mask = (1 << bits) - 1;
r += (*p & mask) << count_bits;
*p >>= bits;
// The region we're extracting ends in the middle of this byte
// Set the mask to cover that region; add those to the result
// (after shiting it to the correct position)
unsigned mask = ((1 << bits) - 1) << (bits_in_byte - bits);
r += (*p & mask) >> (bits_in_byte - bits);

bits_in_byte -= bits;

// And remove those bits from the byte (so it doesn't interfer
// with the next field we extract)
*p &= ~mask;
}
return r;
}
Expand Down
1 change: 1 addition & 0 deletions stl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <memory>
#include <stdexcept>
#include "api.h"

//
Expand Down
Loading