const size_t n = s.length() / 8; vector<uint8_t> a(n); for(size_t block = 0; block < n; block++) { uint8_t acc = 0; const size_t start = block * 8; for(size_t offset = start; offset < start + 8; offset++) { acc = (acc << 1) + (s[offset] - '0'); } a[block] = acc; }