cpp cast: added const versions
added bit-counting code