C++ Binary Matching