1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <vector>
#include <cstdint>
// because I don't have recd
#include <ctime>
#include <cstdlib>
// to print something quick
#include <iterator>
#include <algorithm>
std::vector< bool > get_vec( void )
{
int corrected_array[72] = {0};
for ( int i=0; i<12; i++) //error corrected "hex-bits" back to binary
{
for ( int j = 0; j<6; j++)
{
int mask = 1 << (5 - j);
corrected_array[i*6 + j] = rand() % 2 ;
}
}
std::vector<bool> ret( corrected_array, corrected_array + 72 );
std::copy( ret.begin(), ret.end(), std::ostream_iterator<bool>( std::cout, "" ));
std::cout << std::endl;
return ret;
}
template<class X>
uint64_t extract(const X& in, const size_t bits[], size_t bits_sz)
{
uint64_t x = 0LL;
for(size_t i = 0; i < bits_sz; ++i) {
x = (x << 1) | (in[bits[i]] ? 1 : 0);
}
return x;
}
uint16_t lcf( void )
{
const size_t LCF_BITS[] = {
0, 1, 2, 3, 4, 5, 6 , 7
};
const size_t LCF_BITS_SZ = sizeof(LCF_BITS) / sizeof(LCF_BITS[0]);
const uint16_t lcf = extract(get_vec(), LCF_BITS, LCF_BITS_SZ);
return lcf;
}
int main( void )
{
srand( time(0) );
std::cout << lcf() << std::endl;
return 0;
}
| |