00001 /** 00002 \file Robots/LoBot/util/LoBits.H 00003 \brief Bit fiddling functions. 00004 */ 00005 00006 // //////////////////////////////////////////////////////////////////// // 00007 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00008 // by the University of Southern California (USC) and the iLab at USC. // 00009 // See http://iLab.usc.edu for information about this project. // 00010 // //////////////////////////////////////////////////////////////////// // 00011 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00012 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00013 // in Visual Environments, and Applications'' by Christof Koch and // 00014 // Laurent Itti, California Institute of Technology, 2001 (patent // 00015 // pending; application number 09/912,225 filed July 23, 2001; see // 00016 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00017 // //////////////////////////////////////////////////////////////////// // 00018 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00019 // // 00020 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00021 // redistribute it and/or modify it under the terms of the GNU General // 00022 // Public License as published by the Free Software Foundation; either // 00023 // version 2 of the License, or (at your option) any later version. // 00024 // // 00025 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00026 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00027 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00028 // PURPOSE. See the GNU General Public License for more details. // 00029 // // 00030 // You should have received a copy of the GNU General Public License // 00031 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00032 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00033 // Boston, MA 02111-1307 USA. // 00034 // //////////////////////////////////////////////////////////////////// // 00035 // 00036 // Primary maintainer for this file: mviswana usc edu 00037 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/util/LoBits.H $ 00038 // $Id: LoBits.H 13037 2010-03-23 01:00:53Z mviswana $ 00039 // 00040 00041 #ifndef LOBOT_BIT_FIDDLING_UTILITIES_DOT_H 00042 #define LOBOT_BIT_FIDDLING_UTILITIES_DOT_H 00043 00044 //----------------------------- NAMESPACE ------------------------------- 00045 00046 namespace lobot { 00047 00048 //---------------------- BIT FIDDLING FUNCTIONS ------------------------- 00049 00050 /// Stuff two 16-bit ints into a long 00051 inline unsigned long make_long(int hi, int lo) 00052 { 00053 return ((hi & 0xFFFF) << 16) | (lo & 0xFFFF) ; 00054 } 00055 00056 /// Extract the lower 16 bits of a long 00057 inline int loword(unsigned long L) 00058 { 00059 return static_cast<int>(L & 0xFFFF) ; 00060 } 00061 00062 /// Extract the higher 16 bits of a long 00063 inline int hiword(unsigned long L) 00064 { 00065 return loword(L >> 16) ; 00066 } 00067 00068 /// Stuff two signed 8-bit ints into a single 16-bit int 00069 inline int make_word(int hi, int lo) 00070 { 00071 return (hi << 8) | (lo & 0xFF) ; 00072 } 00073 00074 /// Stuff two unsigned 8-bit ints into a single 16-bit int 00075 inline int make_uword(int hi, int lo) 00076 { 00077 return ((hi << 8) & 0xFF00) | (lo & 0xFF) ; 00078 } 00079 00080 /// Extract the low byte of a 16-bit word 00081 inline char lobyte(short int word) 00082 { 00083 return static_cast<char>(word & 0xFF) ; 00084 } 00085 00086 /// Extract the high byte of a 16-bit word 00087 inline char hibyte(short int word) 00088 { 00089 return lobyte(word >> 8) ; 00090 } 00091 00092 /// Set a bit in a register to the specified value. The bit to be set or 00093 /// cleared is identified by the given mask. 00094 int set_bit(int reg, int mask, bool val) ; 00095 00096 /// Force the supplied number to be an odd number 00097 inline int force_odd(int n) 00098 { 00099 return n | 1 ; 00100 } 00101 00102 /// Force the supplied number to be an even number 00103 inline int force_even(int n) 00104 { 00105 return n & (~1) ; 00106 } 00107 00108 //----------------------------------------------------------------------- 00109 00110 } // end of namespace encapsulating this file's definitions 00111 00112 #endif 00113 00114 /* So things look consistent in everyone's emacs... */ 00115 /* Local Variables: */ 00116 /* indent-tabs-mode: nil */ 00117 /* End: */