Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 27th, 2006, 06:25 AM
PengYu.UT@gmail.com
Guest
 
Posts: n/a
Default bitset rotational shift?

I need to do rotational shift on bitset. But I couldn't find that
operation in the standard. Is there any workaround or other packages to
do this?

Thanks,
Peng

  #2  
Old March 27th, 2006, 01:45 PM
Howard Hinnant
Guest
 
Posts: n/a
Default Re: bitset rotational shift?

In article <1143439864.704032.283850@i39g2000cwa.googlegroups .com>,
"PengYu.UT@gmail.com" <PengYu.UT@gmail.com> wrote:
[color=blue]
> I need to do rotational shift on bitset. But I couldn't find that
> operation in the standard. Is there any workaround or other packages to
> do this?[/color]

You can do it the same way you would on an unsigned integral type (which
shifts):

#include <bitset>
#include <string>
#include <iostream>

template <std::size_t N>
inline
void
rotate(std::bitset<N>& b, unsigned m)
{
b = b << m | b >> (N-m);
}

int main()
{
std::bitset<20> b(std::string("00001111111111111111"));
std::cout << b << '\n';
rotate(b, 4);
std::cout << b << '\n';
}
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles