Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bit_shift.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 134241a8da918ae3d7664c0e45c2ef0db141a531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

#include "../std/limits.hpp"

namespace bits
{
  template <class T>
  struct bits_of
  {
    enum
    {
      value = sizeof(T) * CHAR_BIT
    };
  };

  template <class T>
  T ror(T val, unsigned int n)
  {
      enum
      {
        bits = bits_of<T>::value
      };
      n = n % bits;
      return (val >> n) | (val << (bits - n));
  }
}