Mobil_surveillance_system 1
Bitmanip.h
Go to the documentation of this file.
00001 #ifndef BITMANIP_H_
00002 #define BITMANIP_H_
00003 
00005 
00011 #define BIG_ENDIAN      // now we're using big endian
00012 
00013 /* ***********************************************************************
00014  * 
00015  * Usage: Before include this file refer to the used endianess and define
00016  * BIG_ENDIAN if the used endianness is big-endian otherwise define LITTLE_ENDIAN
00017  * 
00018  * ***********************************************************************
00019  */
00020 
00021 #ifdef BIG_ENDIAN       // if the used endiannes is big-endian
00022 
00023 /**************************************************************************
00024  * 
00025  *  In this case a byte variable representation is something like this.
00026  * 
00027  *  First byte (lowest address)  Middle bytes   Last byte(highest address)
00028  *  most significant bit            ....            least significant bit 
00029  * 
00030  **************************************************************************/
00031 
00033 #define SET_BIT(variable, n)                ((variable) |= (1<<(n)))        
00034 #define CLEAR_BIT(variable, n)              ((variable) &= ~(1<<(n)))       
00035 #define TOGGLE_BIT(variable, n)             ((variable) ^= (1<<(n)))
00036 #define TEST_BIT(variable, n)               ((variable) & (1<<(n))) 
00037 
00039 #define OR(variable1, variable2)            ((variable1) |= (variable2))
00040 #define AND(variable1, variable2)           ((variable1) &= (variable2))
00041 #define XOR(variable1, variable2)           ((variable1) ^= (variable2))
00042 
00044 #define MULTIPLY_BY_2(variable, n)          ((variable) << (n))
00045 #define DIVIDED_BY_2(variable, n)           ((variable) >> (n))
00046 
00048 #define GET_LOWER_NIBBLE(variable)          ((variable) &= 0x0F)                
00049 #define GET_UPPER_NIBBLE(variable)          ((variable) &= 0xF0)
00050 
00051 #endif // BIG_ENDIAN
00052 
00053 #ifdef LITTLE_ENDIAN    // if the used endiannes is little-endian
00054 
00055 /**************************************************************************
00056  * 
00057  *  In this case a byte variable representation is something like this.
00058  * 
00059  *  First byte (lowest address)  Middle bytes   Last byte(highest address)
00060  *  least significant bit           ....            most significant bit 
00061  * 
00062  **************************************************************************/
00063 
00065 #define SET_BIT(variable, n)                ((variable) |= (1>>(n)))        
00066 #define CLEAR_BIT(variable, n)              ((variable) &= ~(1>>(n)))       
00067 #define TOGGLE_BIT(variable, n)             ((variable) ^= (1>>(n)))
00068 #define TEST_BIT(variable, n)               ((variable) & (1>>(n))) 
00069 
00071 #define OR(variable1, variable2)            ((variable1) |= (variable2))
00072 #define AND(variable1, variable2)           ((variable1) &= (variable2))
00073 #define XOR(variable1, variable2)           ((variable1) ^= (variable2))
00074 
00076 #define MULTIPLY_BY_2(variable, n)          ((variable) >> (n))
00077 #define DIVIDED_BY_2(variable, n)           ((variable) << (n)) 
00078 
00080 #define GET_LOWER_NIBBLE(variable)          ((variable) &= 0xF0)                
00081 #define GET_UPPER_NIBBLE(variable)          ((variable) &= 0x0F)    
00082 
00083 #endif // LITTLE_ENDIAN
00084 
00085 #endif /*BITMANIP_H_*/
 All Data Structures Files Functions Variables Typedefs Enumerations Defines