Split std :: bitset in two halves?

I am using DES algorithm and I need to split std::bitset<56> permutationKeyinto two halves.

std::bitset<56> permutationKey(0x133457799BBCDF);
std::bitset<28> leftKey;
std::bitset<28> rightKey;

std::bitset<56> divider(0b00000000000000000000000000001111111111111111111111111111);

rightKey = permutationKey & divider;
leftKey = (permutationKey >> 28) & divider;

I tried using bitset<56>for bitset<28>, but that did not work.

Another way to achieve the same thing is to loop over and assign each bit separately. I want to achieve this without using loops, there must be another way.

I was able to do this with primitive types

uint64_t key = 0b0001010101010101110110001100001110000011111100000000011111000000;
                    //00010101.01010101.11011000.11000011---|---10000011.11110000.00000111.11000000
uint32_t right = (uint32_t)key;
uint32_t left = key >> 32;

How can I split bitsetas follows?

+4
source share
1 answer
std::bitset<56> permutationKey(0x133457799BBCDF);
std::bitset<56> divider(0b00000000000000000000000000001111111111111111111111111111);

auto rightKey = std::bitset<28> ( (permutationKey & divider).to_ulong() );
auto leftKey = std::bitset<28> ( ((permutationKey >> 28) & divider).to_ulong() );
+4
source

All Articles