rewrite bits in C++