#include <sstream>
#include <string>
#include <bitset>
#include <iostream>
#include <iomanip>
int main()
{
const std::string test[] = { "...|N|Y|N|N|...", "...|Y|N|Y|N|...", "...|N|Y|Y|N|..." } ;
for( const std::string& str : test )
{
std::istringstream stm(str) ;
// parse the four Y/N into bool values
// and form a bitset of four bits with with 'Y' == 1
constexpr std::size_t NBITS = 4 ;
std::bitset<NBITS> bits ; // set of four bits
char Y_or_N ;
for( std::size_t i = 0 ; i < NBITS ; ++i )
{
stm.ignore( 100, '|' ) ; // throw characters away upto and including the next '|'
stm >> Y_or_N ; // read the next char ('Y' or 'N')
bits[ (NBITS-1) - i ] = Y_or_N == 'Y' ; // set the corrosponding bit to 1 if it is a 'Y'
}
// get the code by converting the bits to an integral value
auto code = bits.to_ulong() ;
// check it out
std::cout << str << " " << bits << " " << std::setw(2) << std::setfill('0') << code << '\n' ;
}
}
I2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGlvbWFuaXA+CgppbnQgbWFpbigpCnsKICAgIGNvbnN0IHN0ZDo6c3RyaW5nIHRlc3RbXSA9IHsgIi4uLnxOfFl8TnxOfC4uLiIsICIuLi58WXxOfFl8TnwuLi4iLCAiLi4ufE58WXxZfE58Li4uIiB9IDsKCiAgICBmb3IoIGNvbnN0IHN0ZDo6c3RyaW5nJiBzdHIgOiB0ZXN0ICkKICAgIHsKICAgICAgICBzdGQ6OmlzdHJpbmdzdHJlYW0gc3RtKHN0cikgOwoKICAgICAgICAvLyBwYXJzZSB0aGUgZm91ciBZL04gaW50byBib29sIHZhbHVlcwogICAgICAgIC8vIGFuZCBmb3JtIGEgYml0c2V0IG9mIGZvdXIgYml0cyB3aXRoIHdpdGggJ1knID09IDEKCiAgICAgICAgY29uc3RleHByIHN0ZDo6c2l6ZV90IE5CSVRTID0gNCA7CiAgICAgICAgc3RkOjpiaXRz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