BitOperations.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <limits.h>
00020 
00021 #include "rqt_multiplot/BitOperations.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Methods                                                                   */
00027 /*****************************************************************************/
00028 
00029 unsigned int BitOperations::revertInt(unsigned int val) {
00030   unsigned int reverse = val;
00031   unsigned int shift = sizeof(unsigned int)*CHAR_BIT-1;
00032 
00033   for (val >>= 1; val; val >>= 1) {
00034     reverse <<= 1;
00035     reverse |= val & 1;
00036     --shift;
00037   }
00038   reverse <<= shift;
00039 
00040   return reverse;
00041 }
00042                
00043 unsigned short BitOperations::revertShort(unsigned short val) {
00044   unsigned short reverse = val;
00045   unsigned short shift = sizeof(unsigned short)*CHAR_BIT-1;
00046 
00047   for (val >>= 1; val; val >>= 1) {
00048     reverse <<= 1;
00049     reverse |= val & 1;
00050     --shift;
00051   }
00052   reverse <<= shift;
00053 
00054   return reverse;
00055 }
00056 
00057 unsigned char BitOperations::revertByte(unsigned char val) {
00058   unsigned char reverse = val;
00059   unsigned char shift = sizeof(unsigned char)*CHAR_BIT-1;
00060 
00061   for (val >>= 1; val; val >>= 1) {
00062     reverse <<= 1;
00063     reverse |= val & 1;
00064     --shift;
00065   }
00066   reverse <<= shift;
00067 
00068   return reverse;
00069 }
00070 
00071 };


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10