[ create a new paste ] login | about

Link: http://codepad.org/x2dS6mD6    [ raw code | output | fork ]

C++, pasted on Sep 30:
#include <string>
#include <vector>

using namespace std;

int main() {
    string s("101010100000000011111111");

    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;
    }

    for(size_t j = 0; j < n; j++)
        printf("%02X", a[j]);
}


Output:
1
AA00FF


Create a new paste based on this one


Comments: