CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
bitset_append.cc
Go to the documentation of this file.
1 
4 #include <iostream>
5 #include <cstdio>
6 
7 namespace bitset_utilities {
8 
10  boost::dynamic_bitset<> append(const boost::dynamic_bitset<> & bs1,
11  const boost::dynamic_bitset<> & bs2)
12  {
13  boost::dynamic_bitset<> result(bs1.size()+bs2.size());
14  unsigned size1 = bs1.size();
15  for(unsigned i = 0; i < size1; ++i)
16  {
17  result[i] = bs1[i];
18  }
19  for(unsigned i = 0; i < bs2.size(); ++i)
20  {
21  result[size1+i] = bs2[i];
22  }
23  return result;
24  }
25 
27  boost::dynamic_bitset<> ushortToBitset(const unsigned int numberOfBits,
28  unsigned short * buf)
29  {
30  boost::dynamic_bitset<> result(numberOfBits);
31  for(unsigned i = 0; i < result.size(); ++i)
32  {
33  result[i] = (buf[i/16]>>(i%16)) & 0x1;
34  }
35  return result;
36  }
37 
38 
40  void bitsetToChar(const boost::dynamic_bitset<> & bs, unsigned char * result)
41  {
42  for(unsigned i = 0; i < bs.size(); ++i)
43  {
44  result[i/8] = (bs[i+7]<<7)+
45  (bs[i+6]<<6)+
46  (bs[i+5]<<5)+
47  (bs[i+4]<<4)+
48  (bs[i+3]<<3)+
49  (bs[i+2]<<2)+
50  (bs[i+1]<<1)+
51  bs[i];
52  i+=7;
53  }
54  }
55 
56  void printWords(const boost::dynamic_bitset<> & bs)
57  {
58  unsigned char words[60000];
59  bitsetToChar(bs, words);
60  unsigned short * buf= (unsigned short *) words;
61  for (int unsigned i=0;i<bs.size()/16;++i) {
62  printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
63  i+=3;
64  }
65  }
66 }
int i
Definition: DBlmapReader.cc:9
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
tuple result
Definition: query.py:137
void printWords(const boost::dynamic_bitset<> &bs)
void bitsetToChar(const boost::dynamic_bitset<> &bs, unsigned char *result)
this method takes bitset obj and returns char * array
boost::dynamic_bitset ushortToBitset(const unsigned int numberOfBits, unsigned short *buf)
this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj...