4
Byte a[2]={85, 15};
Byte b[2]={0};
CFBitVectorRef bv1 = CFBitVectorCreate(kCFAllocatorDefault, a, 16);
CFRange r1 = {3, 8};
CFBitVectorGetBits(bv1, r1, b);

Byte a[2] are "0101 0101 0000 1111", I want to cut the {3,8} (1010 1000) of CFRange into another Byte b[2]. But I got nothing in b[2]. But if I change the range to {0,8} or {8,8}, it works. Why cannot get the bits cross-byte?

Witeman
  • 49
  • 4
  • This looks like a bug in CoreFoundation. `{3, 5}` works, but `{3, 6}` does not. – Martin R Mar 26 '13 at 02:43
  • yup, since {3,5} is still not cross byte, still in the first byte. but {3, 6} does. – Witeman Mar 26 '13 at 15:23
  • Yes, I just wanted to say that the problem is that the problem is really that the range crosses a byte boundary, not the alignment of the range. Btw: the source code is at http://opensource.apple.com/source/CF/CF-744.12/CFBitVector.c, so your can try to find the error (-: I would recommend to file a bug at bugreporter.apple.com. – Martin R Mar 26 '13 at 17:20

1 Answers1

0

Seems like i have exactly the same problem. CFBitVectorGetBits sets my *bytes to nil, when i am using {7,7} range. Found any solution? I'm implementing it by stupidly iterating over bits for now.
EDIT:
Adding code:

CFBitVectorRef source = ... ;// Some source bit vector
CFIndex location = 7;//Current location in bit vector
uint8 *bytes = malloc(sizeof(uint8));
//CFBitVectorGetBits(source, CFRangeMake(location,7), bytes);//This one is bugged
CFBitVectorRef buffer = CFBitVectorCreateMutable(NULL,7);
CFBitVectorSetCount(buffer, 7);
for (CFIndex i=0; i<7; i++)
CFBitVectorSetBitAtIndex(buffer, i, CFBitVectorGetBitAtIndex(source, location+i));
CFBitVectorGetBits(buffer, CFRangeMake(0, 7), bytes);
//Now *bytes contains needed bits

Works as needed.

RavisMsk
  • 86
  • 3