port remaining C++ bits to C