BitOperations.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <limits.h>
20 
22 
23 namespace rqt_multiplot {
24 
25 /*****************************************************************************/
26 /* Methods */
27 /*****************************************************************************/
28 
29 unsigned int BitOperations::revertInt(unsigned int val) {
30  unsigned int reverse = val;
31  unsigned int shift = sizeof(unsigned int)*CHAR_BIT-1;
32 
33  for (val >>= 1; val; val >>= 1) {
34  reverse <<= 1;
35  reverse |= val & 1;
36  --shift;
37  }
38  reverse <<= shift;
39 
40  return reverse;
41 }
42 
43 unsigned short BitOperations::revertShort(unsigned short val) {
44  unsigned short reverse = val;
45  unsigned short shift = sizeof(unsigned short)*CHAR_BIT-1;
46 
47  for (val >>= 1; val; val >>= 1) {
48  reverse <<= 1;
49  reverse |= val & 1;
50  --shift;
51  }
52  reverse <<= shift;
53 
54  return reverse;
55 }
56 
57 unsigned char BitOperations::revertByte(unsigned char val) {
58  unsigned char reverse = val;
59  unsigned char shift = sizeof(unsigned char)*CHAR_BIT-1;
60 
61  for (val >>= 1; val; val >>= 1) {
62  reverse <<= 1;
63  reverse |= val & 1;
64  --shift;
65  }
66  reverse <<= shift;
67 
68  return reverse;
69 }
70 
71 };
static unsigned short revertShort(unsigned short val)
static unsigned int revertInt(unsigned int val)
static unsigned char revertByte(unsigned char val)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44