Tengyu Liu
Tengyu Liu

Reputation: 1253

Easy bit-wise operation on bit string in iOS

I'm working on an iOS app that uses a lot of long bit strings (100b) and a lot of bitwise operations. I know that there is very nice bitset class in c++ but I can't include the header file in Xcode. Apple has a CFBitVector class that supports bit string, but it does not have bitwise manipulation. Is there a way that I can use bit string and make bitwise operation as easy as if I'm dealing with unsigned int (so that bitwise operation is simply a & b)?

Right now what I have is using CFBitVector and make a bunch of function calls for bitwise and, bitwise or, and bitwise not. But in this case a simple one-line bitwise manipulation can result into a 4-line function calling creating a lot of temporary variables I don't really need.

Upvotes: 0

Views: 441

Answers (1)

Martin R
Martin R

Reputation: 539735

(From the comments:) You can mix Objective-C and C++ code if you compile the file as Objective-C++: Simply rename the file extension from .m to .mm in the Xcode project navigator.

When including C++ header files such as <bitset> in your .h file, keep in mind that this will only work if the .h file is included by (Objective-)C++ files, not if it is included by Objective-C files.

Upvotes: 1

Related Questions