|
|
for (i=0; i<6; i++) u0 = rs_codeword[i] ;
u0
u0 = rs_codeword[5] ;
rs_codeword
declared? I see it is an array, but it isn't clear of what type.uint16_t * rs_codeword = new uint16_t[144];
|
|
cw
is filled with 0
|
|
Like so: for (i=0; i<144; i++) { cw[i / 6] |= rs_codeword[i] << (i % 6); } Make sure that cw is filled with 0 EDIT: not tested! |
cw[24]={0};
|
|
will this small amount of code accomplish that? |
rs_codeword
and converts it to 6 bits in cw
.000011100001100011111010101101111001110100001001110100010011... etc. |
000011 |
I don't know what a hex-bit or a 6-bit symbol is? |
110010
so that is a 6-bit symbol, or some say a hex-bit. so in octal it is 062
. 'symbols' are used a lot in digital communication. Now there are two ways to convert that into a 6-bit number, depending upon whether the lowest-order bit comes first, or the highest. |
|
|
#include <iostream> #include <cstdint> #include <bitset> #include <string> #include <vector> std::string to_string( const std::uint8_t* a, std::size_t n ) { std::string result ; using bits = std::bitset<8> ; for( std::size_t i = 0 ; i < n ; ++i ) result += bits( a[i] ).to_string() ; return result ; } template< std::size_t NBITS > std::vector<std::uint8_t> to_n_bit_values( const std::string& str ) { std::vector<std::uint8_t> result ; using bits = std::bitset<NBITS> ; for( std::size_t i = 0 ; i < str.size() ; i += NBITS ) result.push_back( bits( str.substr( i, NBITS ) ).to_ulong() ) ; return result ; } template< std::size_t NBITS = 6 > std::vector<std::uint8_t> to_n_bit_values( const std::uint8_t* a, std::size_t n ) { return to_n_bit_values<NBITS>( to_string(a,n) ) ; } int main() // minimal test driver { constexpr std::size_t N = 6 ; const std::uint8_t a[N] = { 0, 1, 25, 3, 255, 49 } ; for( int i : a ) std::cout << i << ' ' ; std::cout << '\n' ; std::string str = to_string(a,N) ; for( std::size_t i = 0 ; i < str.size() ; i += 8 ) std::cout << str.substr( i, 8 ) << ' ' ; std::cout << '\n' ; for( std::size_t i = 0 ; i < str.size() ; i += 6 ) std::cout << str.substr( i, 6 ) << ' ' ; std::cout << '\n' ; for( auto i : to_n_bit_values<>(a,N) ) std::cout << int(i) << ' ' ; std::cout << '\n' ; } http://coliru.stacked-crooked.com/a/03405dc14340565a |
g++-4.8 -std=c++11 -O2 -Wall -pedantic-errors -pthread main.cpp && ./a.out
|
|
The command line (C++11) is there in the link http://coliru.stacked-crooked.com/a/03405dc14340565a g++-4.8 -std=c++11 -O2 -Wall -pedantic-errors -pthread main.cpp && ./a.out This is the C++98 version: |
|
|
|
|
|
|
Or simplified:
|
|
|
000102030405060710111213141516172021222324252627
|
|
|
|
|
|